diff --git a/product_contract_recurrence_in_price/README.rst b/product_contract_recurrence_in_price/README.rst new file mode 100644 index 0000000000..bc6b5d4d42 --- /dev/null +++ b/product_contract_recurrence_in_price/README.rst @@ -0,0 +1,98 @@ +==================================== +Product Contract Recurrence In Price +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:eb3e8e01c6e7342addae863236c3bce5f99edf1a67d3f35eec1e6f59d91473b0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.0/product_contract_recurrence_in_price + :alt: OCA/contract +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-18-0/contract-18-0-product_contract_recurrence_in_price + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of ``product_contract`` to add an +option to compute the total amounts on "contract" Sale Order lines, +including every invoicing planned. + +For instance, a product worth 10€ invoiced every month for one year +would have a total of 120€ (unit_price \* #invoices) instead of 10€ +(unit_price \* quantity). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +- Go to Sales > Products > Products +- In "Product" form, for contract products, select "Include Recurrence + In Price". + +This configuration is also available on each individual Sale Order line, +in the contract configurator (see ``product_contract``). + +When "Include Recurrence In Price" is set, the amounts (total, subtotal, +tax total) of the Sale Order line are multiplied by the number of times +the line will be invoiced. + +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 +------------ + +- Quentin Groulard + +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/product_contract_recurrence_in_price/__init__.py b/product_contract_recurrence_in_price/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/product_contract_recurrence_in_price/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_contract_recurrence_in_price/__manifest__.py b/product_contract_recurrence_in_price/__manifest__.py new file mode 100644 index 0000000000..4fceb9d8b4 --- /dev/null +++ b/product_contract_recurrence_in_price/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Product Contract Recurrence In Price", + "summary": """ + Add an option to include the recurrences + in the total of a Sale Order Line. + """, + "version": "18.0.1.0.0", + "category": "Contract Management", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/contract", + "depends": ["product_contract"], + "data": [ + "views/product_template.xml", + "views/sale_order.xml", + "wizards/product_contract_configurator_views.xml", + ], + "assets": { + "web.assets_backend": ["product_contract_recurrence_in_price/static/src/js/*"] + }, +} diff --git a/product_contract_recurrence_in_price/models/__init__.py b/product_contract_recurrence_in_price/models/__init__.py new file mode 100644 index 0000000000..da6e90be70 --- /dev/null +++ b/product_contract_recurrence_in_price/models/__init__.py @@ -0,0 +1,3 @@ +from . import product_template +from . import sale_order_line_contract_mixin +from . import sale_order_line diff --git a/product_contract_recurrence_in_price/models/product_template.py b/product_contract_recurrence_in_price/models/product_template.py new file mode 100644 index 0000000000..3722dc78a2 --- /dev/null +++ b/product_contract_recurrence_in_price/models/product_template.py @@ -0,0 +1,13 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + include_recurrence_in_price = fields.Boolean( + help="The amounts of the Sale Order Line will be multiplied" + "by the number of times the line will be invoiced." + ) diff --git a/product_contract_recurrence_in_price/models/sale_order_line.py b/product_contract_recurrence_in_price/models/sale_order_line.py new file mode 100644 index 0000000000..4beffa3b0a --- /dev/null +++ b/product_contract_recurrence_in_price/models/sale_order_line.py @@ -0,0 +1,34 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _prepare_base_line_for_taxes_computation(self, **kwargs): + """ + This is the base method for all line amounts computations. + For 'include_recurrence_in_price' lines, we multiply the quantity by + the number of times the line will be invoiced. + """ + self.ensure_one() + if self.include_recurrence_in_price: + return self.env["account.tax"]._prepare_base_line_for_taxes_computation( + self, + **{ + "tax_ids": self.tax_id, + "quantity": self.product_uom_qty * self.recurring_invoicing_number, + "partner_id": self.order_id.partner_id, + "currency_id": self.order_id.currency_id + or self.order_id.company_id.currency_id, + "rate": self.order_id.currency_rate, + **kwargs, + }, + ) + return super()._prepare_base_line_for_taxes_computation(**kwargs) + + @api.depends("recurring_invoicing_number", "include_recurrence_in_price") + def _compute_amount(self): + return super()._compute_amount() diff --git a/product_contract_recurrence_in_price/models/sale_order_line_contract_mixin.py b/product_contract_recurrence_in_price/models/sale_order_line_contract_mixin.py new file mode 100644 index 0000000000..8e9d9e1641 --- /dev/null +++ b/product_contract_recurrence_in_price/models/sale_order_line_contract_mixin.py @@ -0,0 +1,64 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class SaleOrderLineContractMixin(models.AbstractModel): + _inherit = "sale.order.line.contract.mixin" + + include_recurrence_in_price = fields.Boolean( + help="The amounts of the Sale Order Line will be multiplied" + "by the number of times the line will be invoiced.", + compute="_compute_product_contract_data", + precompute=True, + store=True, + readonly=False, + ) + recurring_invoicing_number = fields.Float( + compute="_compute_recurring_invoice_number", + digits=(16, 1), + help="Number of times a line will be invoiced.", + store=True, + readonly=False, + precompute=True, + ) + + @api.depends("product_id") + def _compute_product_contract_data(self): + res = super()._compute_product_contract_data() + for rec in self: + rec.include_recurrence_in_price = ( + rec.product_id.is_contract + and rec.product_id.include_recurrence_in_price + ) + return res + + @api.depends("date_start", "date_end", "recurring_interval", "recurring_rule_type") + def _compute_recurring_invoice_number(self): + for rec in self: + if ( + not rec.date_start + or not rec.date_end + or not rec.recurring_interval + or not rec.recurring_rule_type + ): + rec.recurring_invoicing_number = 0 + continue + days_total = (rec.date_end - rec.date_start).days + if rec.recurring_rule_type == "dayly": + interval_number = days_total + elif rec.recurring_rule_type == "weekly": + interval_number = days_total / 7 + elif rec.recurring_rule_type in ("monthly", "monthlylastday"): + interval_number = days_total / (365.25 / 12) + elif rec.recurring_rule_type == "quarterly": + interval_number = days_total / (365.25 / 4) + elif rec.recurring_rule_type == "semesterly": + interval_number = days_total / (365.25 / 2) + elif rec.recurring_rule_type == "yearly": + interval_number = days_total / 365.25 + else: + raise ValidationError(_("Invalid recurring_rule_type.")) + rec.recurring_invoicing_number = interval_number / rec.recurring_interval diff --git a/product_contract_recurrence_in_price/pyproject.toml b/product_contract_recurrence_in_price/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/product_contract_recurrence_in_price/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_contract_recurrence_in_price/readme/CONTRIBUTORS.md b/product_contract_recurrence_in_price/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..01f3219a11 --- /dev/null +++ b/product_contract_recurrence_in_price/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Quentin Groulard \<\> diff --git a/product_contract_recurrence_in_price/readme/DESCRIPTION.md b/product_contract_recurrence_in_price/readme/DESCRIPTION.md new file mode 100644 index 0000000000..835758d0fa --- /dev/null +++ b/product_contract_recurrence_in_price/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module extends the functionality of ``product_contract`` to add an option to compute +the total amounts on "contract" Sale Order lines, including every invoicing planned. + +For instance, a product worth 10€ invoiced every month for one year would have a total +of 120€ (unit_price * #invoices) instead of 10€ (unit_price * quantity). diff --git a/product_contract_recurrence_in_price/readme/USAGE.md b/product_contract_recurrence_in_price/readme/USAGE.md new file mode 100644 index 0000000000..43ed6f8995 --- /dev/null +++ b/product_contract_recurrence_in_price/readme/USAGE.md @@ -0,0 +1,10 @@ +To use this module, you need to: + +- Go to Sales > Products > Products +- In "Product" form, for contract products, select "Include Recurrence In Price". + +This configuration is also available on each individual Sale Order line, in the contract +configurator (see ``product_contract``). + +When "Include Recurrence In Price" is set, the amounts (total, subtotal, tax total) of the +Sale Order line are multiplied by the number of times the line will be invoiced. diff --git a/product_contract_recurrence_in_price/static/description/icon.png b/product_contract_recurrence_in_price/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/product_contract_recurrence_in_price/static/description/icon.png differ diff --git a/product_contract_recurrence_in_price/static/description/index.html b/product_contract_recurrence_in_price/static/description/index.html new file mode 100644 index 0000000000..c56c32b9c8 --- /dev/null +++ b/product_contract_recurrence_in_price/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +Product Contract Recurrence In Price + + + +
+

Product Contract Recurrence In Price

+ + +

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

+

This module extends the functionality of product_contract to add an +option to compute the total amounts on “contract” Sale Order lines, +including every invoicing planned.

+

For instance, a product worth 10€ invoiced every month for one year +would have a total of 120€ (unit_price * #invoices) instead of 10€ +(unit_price * quantity).

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  • Go to Sales > Products > Products
  • +
  • In “Product” form, for contract products, select “Include Recurrence +In Price”.
  • +
+

This configuration is also available on each individual Sale Order line, +in the contract configurator (see product_contract).

+

When “Include Recurrence In Price” is set, the amounts (total, subtotal, +tax total) of the Sale Order line are multiplied by the number of times +the line will be invoiced.

+
+
+

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/product_contract_recurrence_in_price/static/src/js/contract_configurator_controller.esm.js b/product_contract_recurrence_in_price/static/src/js/contract_configurator_controller.esm.js new file mode 100644 index 0000000000..f99e2bd952 --- /dev/null +++ b/product_contract_recurrence_in_price/static/src/js/contract_configurator_controller.esm.js @@ -0,0 +1,12 @@ +/** @odoo-module **/ + +import {patch} from "@web/core/utils/patch"; +import {ProductContractConfiguratorController} from "@product_contract/js/contract_configurator_controller.esm"; + +patch(ProductContractConfiguratorController.prototype, { + _getProductContractConfiguration(record) { + const config = super._getProductContractConfiguration(record); + config.include_recurrence_in_price = record.data.include_recurrence_in_price; + return config; + }, +}); diff --git a/product_contract_recurrence_in_price/static/src/js/sale_product_field.esm.js b/product_contract_recurrence_in_price/static/src/js/sale_product_field.esm.js new file mode 100644 index 0000000000..64e62729e1 --- /dev/null +++ b/product_contract_recurrence_in_price/static/src/js/sale_product_field.esm.js @@ -0,0 +1,15 @@ +/** @odoo-module **/ + +import {patch} from "@web/core/utils/patch"; +import {SaleOrderLineProductField} from "@sale/js/sale_product_field"; + +patch(SaleOrderLineProductField.prototype, { + get contractContext() { + const context = super.contractContext; + return { + ...context, + default_include_recurrence_in_price: + this.props.record.data.include_recurrence_in_price, + }; + }, +}); diff --git a/product_contract_recurrence_in_price/tests/__init__.py b/product_contract_recurrence_in_price/tests/__init__.py new file mode 100644 index 0000000000..6f699d0d8b --- /dev/null +++ b/product_contract_recurrence_in_price/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order diff --git a/product_contract_recurrence_in_price/tests/test_sale_order.py b/product_contract_recurrence_in_price/tests/test_sale_order.py new file mode 100644 index 0000000000..fcf68b29e3 --- /dev/null +++ b/product_contract_recurrence_in_price/tests/test_sale_order.py @@ -0,0 +1,41 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.product_contract.tests.test_sale_order import ( + TestSaleOrder as TestSaleOrderBase, +) + + +class TestSaleOrder(TestSaleOrderBase): + def test_compute_amount(self): + """ + Check that recurrence is taken into account in line amounts. + A SO line recurrent over 2 years and invoiced every 4 months will + be invoiced 6 times in total. + """ + tax = self.env["account.tax"].create( + { + "name": "10% tax", + "amount_type": "percent", + "amount": 10, + } + ) + self.order_line1.update( + { + "price_unit": 100, + "product_uom_qty": 10, + "recurrence_number": 2, + "recurrence_interval": "yearly", + "recurring_interval": 4, + "recurring_rule_type": "monthly", + "tax_id": [(4, tax.id)], + } + ) + self.assertEqual(self.order_line1.price_subtotal, 1000) + self.assertEqual(self.order_line1.price_tax, 100) + self.assertEqual(self.order_line1.price_total, 1100) + self.order_line1.include_recurrence_in_price = True + self.assertEqual(self.order_line1.recurring_invoicing_number, 6) + self.assertEqual(self.order_line1.price_subtotal, 6000) + self.assertEqual(self.order_line1.price_tax, 600) + self.assertEqual(self.order_line1.price_total, 6600) diff --git a/product_contract_recurrence_in_price/views/product_template.xml b/product_contract_recurrence_in_price/views/product_template.xml new file mode 100644 index 0000000000..b01c873bdc --- /dev/null +++ b/product_contract_recurrence_in_price/views/product_template.xml @@ -0,0 +1,17 @@ + + + + + product.template + + + + + + + + diff --git a/product_contract_recurrence_in_price/views/sale_order.xml b/product_contract_recurrence_in_price/views/sale_order.xml new file mode 100644 index 0000000000..7287862181 --- /dev/null +++ b/product_contract_recurrence_in_price/views/sale_order.xml @@ -0,0 +1,23 @@ + + + + + sale.order + + + + + + + + + + + diff --git a/product_contract_recurrence_in_price/wizards/product_contract_configurator_views.xml b/product_contract_recurrence_in_price/wizards/product_contract_configurator_views.xml new file mode 100644 index 0000000000..5ae3ab0911 --- /dev/null +++ b/product_contract_recurrence_in_price/wizards/product_contract_configurator_views.xml @@ -0,0 +1,15 @@ + + + + product.contract.configurator + + + + + + + +