Skip to content

[ADD] contract_timesheet_monitoring #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions contract_timesheet_monitoring/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
=============================
Contract timesheet monitoring
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:00fb3cdc565442ffcd3351e97d0516ce6f4ceb55402981b183f7e717a1e23173
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-coopiteasy%2Faddons-lightgray.png?logo=github
:target: https://github.com/coopiteasy/addons/tree/16.0/contract_timesheet_monitoring
:alt: coopiteasy/addons

|badge1| |badge2| |badge3|

This module was developped for clients paying a subscription fee for
functional support. We wanted to invoice a fixed amount per period, but
invoice excess time. This module provide a way for the clients and the
service provider to monitor the time spent to compare it with the
quantity bought.

**Table of contents**

.. contents::
:local:

Usage
=====

The time spent for the current period is indicated in the contract line.
Time spent for past periods is indicated in the previous invoices. Note
: this might be confusing if the contract is configured to create
invoices at the begining of the period.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/coopiteasy/addons/issues/new?body=module:%20contract_timesheet_monitoring%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Coop IT Easy SC

Maintainers
-----------

This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/16.0/contract_timesheet_monitoring>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions contract_timesheet_monitoring/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions contract_timesheet_monitoring/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2017 Tecnativa - Luis M. Ontalba
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Contract timesheet monitoring",
"summary": "Compute time spent on service contracts",
"version": "16.0.1.0.0",
"category": "Sales",
"author": "Coop IT Easy SC, Odoo Community Association (OCA)",
"website": "https://github.com/coopiteasy/addons",
"depends": ["contract", "hr_timesheet", "contract_invoice_start_end_dates"],
"data": [
"views/contract.xml",
"views/account_move.xml",
"views/account_invoice_report.xml",
"views/contract_portal_templates.xml",
],
"license": "AGPL-3",
"installable": True,
}
3 changes: 3 additions & 0 deletions contract_timesheet_monitoring/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import contract_line
from . import account_move_line
from . import account_analytic_account
19 changes: 19 additions & 0 deletions contract_timesheet_monitoring/models/account_analytic_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from odoo import models


class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account"

def get_time_spent_for_period(self, start_date, end_date=None):
analytic_account_lines = self.line_ids
timesheets = analytic_account_lines.filtered(
# keep only timesheets
# ensure the uom is the same as the one configure for the project
# timesheets (hours or day)
lambda x: (x.encoding_uom_id == x.project_id.timesheet_encode_uom_id)
)
if timesheets:
time_spent_on_account = timesheets.filtered(
lambda x: (x.date >= start_date)
).mapped("unit_amount")
return sum(time_spent_on_account)
38 changes: 38 additions & 0 deletions contract_timesheet_monitoring/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2016 Tecnativa - Carlos Dauden
# Copyright 2018 ACSONE SA/NV.
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

time_spent = fields.Float(
string="Time Spent this Period", compute="_compute_time_spent"
)

# this method is a duplicate from get_time_spent in contract.line
# but this is due to the fact that contract line tend to mimic account move lines
# it make sense to keep these methods separated.
def get_time_spent(self, analytic_distribution, start_date, end_date=None):
total_time_spent = 0
for analytic_account, percentage in analytic_distribution.items():
analytic_account = self.env["account.analytic.account"].browse(
int(analytic_account)
)
time_spent_on_account = analytic_account.get_time_spent_for_period(
start_date
)
total_time_spent += time_spent_on_account * percentage / 100
return total_time_spent

def _compute_time_spent(self):
for line in self:
if line.analytic_distribution and line.start_date:
line.time_spent = line.get_time_spent(
line.analytic_distribution, line.start_date, line.end_date
)
else:
line.time_spent = False
34 changes: 34 additions & 0 deletions contract_timesheet_monitoring/models/contract_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from odoo import fields, models


class ContractLine(models.Model):
_inherit = "contract.line"

time_spent = fields.Float(
string="Time Spent this Period", compute="_compute_time_spent"
)

# this method is a duplicate from get_time_spent in account.move.line
# but this is due to the fact that contract line tend to mimic account move lines
# it make sense to keep these methods separated.
def get_time_spent(self, analytic_distribution, start_date, end_date=None):
total_time_spent = 0
for analytic_account, percentage in analytic_distribution.items():
analytic_account = self.env["account.analytic.account"].browse(
int(analytic_account)
)
time_spent_on_account = analytic_account.get_time_spent_for_period(
start_date
)
total_time_spent += time_spent_on_account * percentage / 100
return total_time_spent

def _compute_time_spent(self):
for line in self:
if line.analytic_distribution:
period_start_date = line.last_date_invoiced or line.date_start
line.time_spent = line.get_time_spent(
line.analytic_distribution, period_start_date
)
else:
line.time_spent = False
6 changes: 6 additions & 0 deletions contract_timesheet_monitoring/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

This module was developped for clients paying a subscription fee for functional support. We wanted to invoice a fixed amount per period, but invoice excess time.
This module provide a way for the clients and the service provider to monitor the time spent to compare it with the quantity bought.



2 changes: 2 additions & 0 deletions contract_timesheet_monitoring/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The time spent for the current period is indicated in the contract line. Time spent for past periods is indicated in the previous invoices.
Note : this might be confusing if the contract is configured to create invoices at the begining of the period.
Loading