diff --git a/contract_timesheet_monitoring/README.rst b/contract_timesheet_monitoring/README.rst new file mode 100644 index 000000000..32f52fcbb --- /dev/null +++ b/contract_timesheet_monitoring/README.rst @@ -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 `_. +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 `_. + +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 `_ project on GitHub. + +You are welcome to contribute. diff --git a/contract_timesheet_monitoring/__init__.py b/contract_timesheet_monitoring/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/contract_timesheet_monitoring/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/contract_timesheet_monitoring/__manifest__.py b/contract_timesheet_monitoring/__manifest__.py new file mode 100644 index 000000000..e55bbb672 --- /dev/null +++ b/contract_timesheet_monitoring/__manifest__.py @@ -0,0 +1,19 @@ +# 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/product_template_view.xml", + "views/contract_portal_templates.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/contract_timesheet_monitoring/models/__init__.py b/contract_timesheet_monitoring/models/__init__.py new file mode 100644 index 000000000..48294c074 --- /dev/null +++ b/contract_timesheet_monitoring/models/__init__.py @@ -0,0 +1,3 @@ +from . import contract_line +from . import account_analytic_account +from . import product_template diff --git a/contract_timesheet_monitoring/models/account_analytic_account.py b/contract_timesheet_monitoring/models/account_analytic_account.py new file mode 100644 index 000000000..dfcd16434 --- /dev/null +++ b/contract_timesheet_monitoring/models/account_analytic_account.py @@ -0,0 +1,18 @@ +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 + lambda x: (x.product_uom_id.measure_type == "time") + ) + if timesheets: + if start_date: + timesheets = timesheets.filtered( + lambda x: (x.date >= start_date) + ) + return sum(timesheets.mapped("unit_amount")) diff --git a/contract_timesheet_monitoring/models/contract_line.py b/contract_timesheet_monitoring/models/contract_line.py new file mode 100644 index 000000000..90d6d83ad --- /dev/null +++ b/contract_timesheet_monitoring/models/contract_line.py @@ -0,0 +1,41 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class ContractLine(models.Model): + _inherit = "contract.line" + + time_spent = fields.Float( + string="Time Spent", compute="_compute_time_spent" + ) + time_available = fields.Integer(related="product_id.time_available") + + time_remaining = fields.Float( + string="Time Remaining", compute="_compute_time_remaining" + ) + date_of_last_invoice = fields.Date(compute="_get_date_of_last_invoice") + + def _get_period_start_date(self): + if self.recurring_invoicing_type == 'post-paid': + start_date = self.recurring_next_dat + else: + start_date = self.recurring_next_date - self.get_relative_delta( + self.recurring_rule_type, self.recurring_interval + ) + return start_date + + @api.depends("analytic_account_id.line_ids") + def _compute_time_spent(self): + for line in self: + if line.analytic_account_id: + period_start_date = line._get_period_start_date() + line.time_spent = line.analytic_account_id.get_time_spent_for_period( + period_start_date + ) + else: + line.time_spent = False + + @api.depends("time_available", "time_spent") + def _compute_time_remaining(self): + for line in self: + line.time_remaining = line.time_available - line.time_spent diff --git a/contract_timesheet_monitoring/models/product_template.py b/contract_timesheet_monitoring/models/product_template.py new file mode 100644 index 000000000..6372ba9ab --- /dev/null +++ b/contract_timesheet_monitoring/models/product_template.py @@ -0,0 +1,14 @@ +# Copyright 2023 Coop IT Easy SC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + is_support_product = fields.Boolean() + time_available = fields.Integer( + string="Time available", + default=0, + ) diff --git a/contract_timesheet_monitoring/readme/DESCRIPTION.md b/contract_timesheet_monitoring/readme/DESCRIPTION.md new file mode 100644 index 000000000..7c07c3e31 --- /dev/null +++ b/contract_timesheet_monitoring/readme/DESCRIPTION.md @@ -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. + + + diff --git a/contract_timesheet_monitoring/readme/USAGE.md b/contract_timesheet_monitoring/readme/USAGE.md new file mode 100644 index 000000000..42dd081ad --- /dev/null +++ b/contract_timesheet_monitoring/readme/USAGE.md @@ -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. diff --git a/contract_timesheet_monitoring/static/description/index.html b/contract_timesheet_monitoring/static/description/index.html new file mode 100644 index 000000000..821f15548 --- /dev/null +++ b/contract_timesheet_monitoring/static/description/index.html @@ -0,0 +1,420 @@ + + + + + +Contract timesheet monitoring + + + +
+

Contract timesheet monitoring

+ + +

Beta License: AGPL-3 coopiteasy/addons

+

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

+ +
+

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. +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.

+

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 project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/contract_timesheet_monitoring/views/contract.xml b/contract_timesheet_monitoring/views/contract.xml new file mode 100644 index 000000000..e5e74d7e0 --- /dev/null +++ b/contract_timesheet_monitoring/views/contract.xml @@ -0,0 +1,15 @@ + + + + contract.contract.form.view + contract.contract + + + + + + + + + + diff --git a/contract_timesheet_monitoring/views/contract_portal_templates.xml b/contract_timesheet_monitoring/views/contract_portal_templates.xml new file mode 100644 index 000000000..cb61fd22d --- /dev/null +++ b/contract_timesheet_monitoring/views/contract_portal_templates.xml @@ -0,0 +1,47 @@ + + + + + diff --git a/contract_timesheet_monitoring/views/product_template_view.xml b/contract_timesheet_monitoring/views/product_template_view.xml new file mode 100644 index 000000000..ab46423b3 --- /dev/null +++ b/contract_timesheet_monitoring/views/product_template_view.xml @@ -0,0 +1,19 @@ + + + + + + product.template.form.view + product.template + + + + + + + + + + + +