diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index 80034f6062b..ab1ecd00156 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -34,6 +34,7 @@ class ContractLine(models.Model): ) company_id = fields.Many2one(related="contract_id.company_id") currency_id = fields.Many2one(related="contract_id.currency_id") + partner_id = fields.Many2one(related="contract_id.partner_id") date_start = fields.Date(required=True) date_end = fields.Date(compute="_compute_date_end", store=True, readonly=False) termination_notice_date = fields.Date( diff --git a/contract_timesheet_invoice_type/README.rst b/contract_timesheet_invoice_type/README.rst new file mode 100644 index 00000000000..50c7083decb --- /dev/null +++ b/contract_timesheet_invoice_type/README.rst @@ -0,0 +1,96 @@ +================== +Contract Timesheet +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7dda3119071689c61cea26bb92ceabe337c1a6d207437833caa853f9170c5ab0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-OCA%2Fcontract-lightgray.png?logo=github + :target: https://github.com/OCA/contract/tree/16.0/contract_timesheet_invoice_type + :alt: OCA/contract +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_timesheet_invoice_type + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This modules adds a Contract field on projects, and sets the timesheet +invoice type based on the product that is used on the contract line. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +Timesheets have a ``timesheet_invoice_type`` field which tells if they +are billable or not, and if billable of which type. In the +``sale_timesheet`` module, this field gets a billable type only when the +timesheet are linked to a sale order line. + +When billing with recurring invoices using the OCA ``contract`` module, +we often work without sale order. So this module is useful to allow +correctly categorizing as billable timesheets on projects that are +billed using recurring contracts. + +Known issues / Roadmap +====================== + +- A link between tasks and contract lines could be added, similar to + what is done for sale order line. + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Stéphane Bidoul stephane.bidoul@acsone.eu + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/contract `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/contract_timesheet_invoice_type/__init__.py b/contract_timesheet_invoice_type/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/contract_timesheet_invoice_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/contract_timesheet_invoice_type/__manifest__.py b/contract_timesheet_invoice_type/__manifest__.py new file mode 100644 index 00000000000..0d09d4e29a7 --- /dev/null +++ b/contract_timesheet_invoice_type/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Timesheet", + "summary": """ + Link projects to sale contracts""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/contract", + "depends": [ + "contract", + "sale_project", + "sale_timesheet", + ], + "data": [ + "views/project_project.xml", + ], + "maintainer": ["sbidoul"], +} diff --git a/contract_timesheet_invoice_type/models/__init__.py b/contract_timesheet_invoice_type/models/__init__.py new file mode 100644 index 00000000000..aaefbcd7b03 --- /dev/null +++ b/contract_timesheet_invoice_type/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_analytic_line +from . import project_project diff --git a/contract_timesheet_invoice_type/models/account_analytic_line.py b/contract_timesheet_invoice_type/models/account_analytic_line.py new file mode 100644 index 00000000000..f08960660ea --- /dev/null +++ b/contract_timesheet_invoice_type/models/account_analytic_line.py @@ -0,0 +1,41 @@ +# Copyright 2024 ASCONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + contract_line_id = fields.Many2one( + related="project_id.contract_line_id", + ) + + @api.depends("contract_line_id.product_id", "amount") + def _compute_timesheet_invoice_type(self): # pylint: disable=missing-return + super()._compute_timesheet_invoice_type() + for rec in self: + if rec.so_line: + # billed via the sale order + continue + if not rec.contract_line_id: + # no contract, let the default algo do it's job + continue + # From here, similar algorithm as in sale_timesheet + product_id = rec.contract_line_id.product_id + if product_id.type != "service": + continue + if product_id.invoice_policy == "delivery": + service_type = product_id.service_type + if service_type == "timesheet": + rec.timesheet_invoice_type = ( + "timesheet_revenues" if rec.amount > 0 else "billable_time" + ) + else: + rec.timesheet_invoice_type = ( + f"billable_{service_type}" + if service_type in ["milestones", "manual"] + else "billable_fixed" + ) + elif product_id.invoice_policy == "order": + rec.timesheet_invoice_type = "billable_fixed" diff --git a/contract_timesheet_invoice_type/models/project_project.py b/contract_timesheet_invoice_type/models/project_project.py new file mode 100644 index 00000000000..42ddcf23653 --- /dev/null +++ b/contract_timesheet_invoice_type/models/project_project.py @@ -0,0 +1,28 @@ +# Copyright 2024 ASCONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProjectProject(models.Model): + _inherit = "project.project" + + contract_line_id = fields.Many2one( + "contract.line", + "Contract Item", + copy=False, + index="btree_not_null", + domain=( + "[('partner_id', '=?', partner_id), " + "'|', ('company_id', '=', False), ('company_id', '=', company_id)]" + ), + help=( + "Recurring invoicing contract item that will be used to " + "determine the timesheet invoicing type." + ), + ) + contract_id = fields.Many2one( + related="contract_line_id.contract_id", + readonly=True, + help="Recurring invoicing contract", + ) diff --git a/contract_timesheet_invoice_type/readme/CONTEXT.md b/contract_timesheet_invoice_type/readme/CONTEXT.md new file mode 100644 index 00000000000..9d3b32b77fd --- /dev/null +++ b/contract_timesheet_invoice_type/readme/CONTEXT.md @@ -0,0 +1,9 @@ +Timesheets have a `timesheet_invoice_type` field which tells if they are +billable or not, and if billable of which type. In the `sale_timesheet` module, +this field gets a billable type only when the timesheet are linked to a sale +order line. + +When billing with recurring invoices using the OCA `contract` module, we often +work without sale order. So this module is useful to allow correctly +categorizing as billable timesheets on projects that are billed using recurring +contracts. diff --git a/contract_timesheet_invoice_type/readme/CONTRIBUTORS.md b/contract_timesheet_invoice_type/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..16c0fd08d03 --- /dev/null +++ b/contract_timesheet_invoice_type/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Stéphane Bidoul diff --git a/contract_timesheet_invoice_type/readme/DESCRIPTION.md b/contract_timesheet_invoice_type/readme/DESCRIPTION.md new file mode 100644 index 00000000000..be62548541a --- /dev/null +++ b/contract_timesheet_invoice_type/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This modules adds a Contract field on projects, and sets the timesheet invoice +type based on the product that is used on the contract line. diff --git a/contract_timesheet_invoice_type/readme/ROADMAP.md b/contract_timesheet_invoice_type/readme/ROADMAP.md new file mode 100644 index 00000000000..bddda52c357 --- /dev/null +++ b/contract_timesheet_invoice_type/readme/ROADMAP.md @@ -0,0 +1,2 @@ +- A link between tasks and contract lines could be added, similar to what is done + for sale order line. diff --git a/contract_timesheet_invoice_type/static/description/icon.png b/contract_timesheet_invoice_type/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/contract_timesheet_invoice_type/static/description/icon.png differ diff --git a/contract_timesheet_invoice_type/static/description/index.html b/contract_timesheet_invoice_type/static/description/index.html new file mode 100644 index 00000000000..19b5edbe479 --- /dev/null +++ b/contract_timesheet_invoice_type/static/description/index.html @@ -0,0 +1,441 @@ + + + + + +Contract Timesheet + + + +
+

Contract Timesheet

+ + +

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runboat

+

This modules adds a Contract field on projects, and sets the timesheet +invoice type based on the product that is used on the contract line.

+

Table of contents

+ +
+

Use Cases / Context

+

Timesheets have a timesheet_invoice_type field which tells if they +are billable or not, and if billable of which type. In the +sale_timesheet module, this field gets a billable type only when the +timesheet are linked to a sale order line.

+

When billing with recurring invoices using the OCA contract module, +we often work without sale order. So this module is useful to allow +correctly categorizing as billable timesheets on projects that are +billed using recurring contracts.

+
+
+

Known issues / Roadmap

+
    +
  • A link between tasks and contract lines could be added, similar to +what is done for sale order line.
  • +
+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/contract project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/contract_timesheet_invoice_type/views/project_project.xml b/contract_timesheet_invoice_type/views/project_project.xml new file mode 100644 index 00000000000..e41f8d600b0 --- /dev/null +++ b/contract_timesheet_invoice_type/views/project_project.xml @@ -0,0 +1,19 @@ + + + + + + project.project + + + + + + + + + + + + diff --git a/setup/contract_timesheet_invoice_type/odoo/addons/contract_timesheet_invoice_type b/setup/contract_timesheet_invoice_type/odoo/addons/contract_timesheet_invoice_type new file mode 120000 index 00000000000..476be1a5851 --- /dev/null +++ b/setup/contract_timesheet_invoice_type/odoo/addons/contract_timesheet_invoice_type @@ -0,0 +1 @@ +../../../../contract_timesheet_invoice_type \ No newline at end of file diff --git a/setup/contract_timesheet_invoice_type/setup.py b/setup/contract_timesheet_invoice_type/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/contract_timesheet_invoice_type/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)