diff --git a/contract_variable_qty_prorated/README.rst b/contract_variable_qty_prorated/README.rst new file mode 100644 index 0000000000..438efeaf3c --- /dev/null +++ b/contract_variable_qty_prorated/README.rst @@ -0,0 +1,96 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================== +Contract Variable Qty Prorated +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ff72cb63aa06a418f71a39644c35ca4000777aa6f61acc546fdfafa70bd669f6 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/contract_variable_qty_prorated + :alt: OCA/contract +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-19-0/contract-19-0-contract_variable_qty_prorated + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a formula to compute prorated quantity to invoice as +extension of the module contract_variable_quantity. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +If this module is installed with product_contract, the quantity field of +sale order lines won't be displayed. + +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 +------------ + +- Souheil Bejaoui +- Thomas Binsfeld + +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. + +.. |maintainer-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui + +Current `maintainer `__: + +|maintainer-sbejaoui| + +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_variable_qty_prorated/__init__.py b/contract_variable_qty_prorated/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/contract_variable_qty_prorated/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/contract_variable_qty_prorated/__manifest__.py b/contract_variable_qty_prorated/__manifest__.py new file mode 100644 index 0000000000..12358b1e4c --- /dev/null +++ b/contract_variable_qty_prorated/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Variable Qty Prorated", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["sbejaoui"], + "website": "https://github.com/OCA/contract", + "depends": ["contract_variable_quantity"], + "data": [ + "data/contract_variable_qty_prorated.xml", + "views/contract_template_line.xml", + ], + "demo": [], +} diff --git a/contract_variable_qty_prorated/data/contract_variable_qty_prorated.xml b/contract_variable_qty_prorated/data/contract_variable_qty_prorated.xml new file mode 100644 index 0000000000..97ec5d4905 --- /dev/null +++ b/contract_variable_qty_prorated/data/contract_variable_qty_prorated.xml @@ -0,0 +1,14 @@ + + + + + Prorated Quantity + +result = 0 +if line: + result = line.quantity * line.compute_prorated(period_first_date, period_last_date, invoice_date) + + + + diff --git a/contract_variable_qty_prorated/i18n/contract_variable_qty_prorated.pot b/contract_variable_qty_prorated/i18n/contract_variable_qty_prorated.pot new file mode 100644 index 0000000000..c6228995e8 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/contract_variable_qty_prorated.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "" diff --git a/contract_variable_qty_prorated/i18n/fr.po b/contract_variable_qty_prorated/i18n/fr.po new file mode 100644 index 0000000000..fa8f5355ac --- /dev/null +++ b/contract_variable_qty_prorated/i18n/fr.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-10-01 09:33+0000\n" +"PO-Revision-Date: 2021-01-04 11:44+0000\n" +"Last-Translator: Rémi \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "Ligne de Contrat" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "Quantité proratisée" diff --git a/contract_variable_qty_prorated/i18n/it.po b/contract_variable_qty_prorated/i18n/it.po new file mode 100644 index 0000000000..d5ef455f23 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-07-31 10:25+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "Riga contratto" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "Quantità ripartita" diff --git a/contract_variable_qty_prorated/i18n/nl.po b/contract_variable_qty_prorated/i18n/nl.po new file mode 100644 index 0000000000..a7ee506fca --- /dev/null +++ b/contract_variable_qty_prorated/i18n/nl.po @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "" diff --git a/contract_variable_qty_prorated/i18n/nl_NL.po b/contract_variable_qty_prorated/i18n/nl_NL.po new file mode 100644 index 0000000000..1aa0c50989 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/nl_NL.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-12-29 10:42+0000\n" +"Last-Translator: Bosd \n" +"Language-Team: none\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "Contractregel" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "Pro rata hoeveelheid" diff --git a/contract_variable_qty_prorated/i18n/pt_BR.po b/contract_variable_qty_prorated/i18n/pt_BR.po new file mode 100644 index 0000000000..cd8ed854e0 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/pt_BR.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-06-17 01:19+0000\n" +"Last-Translator: Fernando Colus \n" +"Language-Team: none\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 3.10\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "Linha de Contrato" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "Quantidade Proporcional (Pró-rata)" diff --git a/contract_variable_qty_prorated/i18n/sv.po b/contract_variable_qty_prorated/i18n/sv.po new file mode 100644 index 0000000000..71a009e616 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/sv.po @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_variable_qty_prorated +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: sv\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: contract_variable_qty_prorated +#: model:ir.model,name:contract_variable_qty_prorated.model_contract_line +msgid "Contract Line" +msgstr "" + +#. module: contract_variable_qty_prorated +#: model:contract.line.qty.formula,name:contract_variable_qty_prorated.contract_variable_qty_prorated +msgid "Prorated Quantity" +msgstr "" diff --git a/contract_variable_qty_prorated/models/__init__.py b/contract_variable_qty_prorated/models/__init__.py new file mode 100644 index 0000000000..6143a36501 --- /dev/null +++ b/contract_variable_qty_prorated/models/__init__.py @@ -0,0 +1 @@ +from . import contract_line diff --git a/contract_variable_qty_prorated/models/contract_line.py b/contract_variable_qty_prorated/models/contract_line.py new file mode 100644 index 0000000000..203261237d --- /dev/null +++ b/contract_variable_qty_prorated/models/contract_line.py @@ -0,0 +1,53 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ContractLine(models.Model): + _inherit = "contract.line" + + def compute_prorated(self, period_first_date, period_last_date, invoice_date): + self.ensure_one() + return self._compute_prorated( + period_first_date, + period_last_date, + invoice_date, + self.recurring_rule_type, + self.recurring_interval, + self.recurring_invoicing_type, + ) + + @api.model + def _compute_prorated( + self, + period_first_date, + period_last_date, + invoice_date, + recurring_rule_type, + recurring_interval, + recurring_invoicing_type, + ): + def _invoiced_days(next_date, last_date): + return (next_date - last_date).days + 1 + + relative_delta = self.get_relative_delta( + recurring_rule_type, recurring_interval + ) + theoretical_next_date = invoice_date + if ( + recurring_rule_type == "monthlylastday" + and recurring_invoicing_type == "post-paid" + ): + relative_delta = self.get_relative_delta("monthly", recurring_interval) + theoretical_next_date += self.get_relative_delta("daily", 1) + + if recurring_invoicing_type == "pre-paid": + theoretical_next_date += relative_delta + theoretical_last_date = theoretical_next_date - relative_delta + theoretical_next_date -= self.get_relative_delta("daily", 1) + real_last_date = period_first_date + real_next_date = period_last_date + return _invoiced_days(real_next_date, real_last_date) / _invoiced_days( + theoretical_next_date, theoretical_last_date + ) diff --git a/contract_variable_qty_prorated/pyproject.toml b/contract_variable_qty_prorated/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/contract_variable_qty_prorated/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/contract_variable_qty_prorated/readme/CONTRIBUTORS.md b/contract_variable_qty_prorated/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..8c0ce2b00a --- /dev/null +++ b/contract_variable_qty_prorated/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Souheil Bejaoui \<\> +- Thomas Binsfeld \<\> diff --git a/contract_variable_qty_prorated/readme/DESCRIPTION.md b/contract_variable_qty_prorated/readme/DESCRIPTION.md new file mode 100644 index 0000000000..3877b5d97e --- /dev/null +++ b/contract_variable_qty_prorated/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds a formula to compute prorated quantity to invoice as +extension of the module contract_variable_quantity. diff --git a/contract_variable_qty_prorated/readme/ROADMAP.md b/contract_variable_qty_prorated/readme/ROADMAP.md new file mode 100644 index 0000000000..cd916969aa --- /dev/null +++ b/contract_variable_qty_prorated/readme/ROADMAP.md @@ -0,0 +1,2 @@ +If this module is installed with product_contract, the quantity field of +sale order lines won't be displayed. diff --git a/contract_variable_qty_prorated/static/description/icon.png b/contract_variable_qty_prorated/static/description/icon.png new file mode 100644 index 0000000000..1dcc49c24f Binary files /dev/null and b/contract_variable_qty_prorated/static/description/icon.png differ diff --git a/contract_variable_qty_prorated/static/description/index.html b/contract_variable_qty_prorated/static/description/index.html new file mode 100644 index 0000000000..4ca03e7968 --- /dev/null +++ b/contract_variable_qty_prorated/static/description/index.html @@ -0,0 +1,439 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Contract Variable Qty Prorated

+ +

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

+

This module adds a formula to compute prorated quantity to invoice as +extension of the module contract_variable_quantity.

+

Table of contents

+ +
+

Known issues / Roadmap

+

If this module is installed with product_contract, the quantity field of +sale order lines won’t be displayed.

+
+
+

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.

+

Current maintainer:

+

sbejaoui

+

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_variable_qty_prorated/tests/__init__.py b/contract_variable_qty_prorated/tests/__init__.py new file mode 100644 index 0000000000..2b7f5ecf77 --- /dev/null +++ b/contract_variable_qty_prorated/tests/__init__.py @@ -0,0 +1 @@ +from . import test_compute_proprata diff --git a/contract_variable_qty_prorated/tests/test_compute_proprata.py b/contract_variable_qty_prorated/tests/test_compute_proprata.py new file mode 100644 index 0000000000..bbdbafa805 --- /dev/null +++ b/contract_variable_qty_prorated/tests/test_compute_proprata.py @@ -0,0 +1,318 @@ +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import Command +from odoo.tests.common import tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("post_install", "-at_install") +class TestProductTemplate(BaseCommon): + """ + These tests verify that prorated invoice amounts are correctly computed + based on recurrence type, interval, invoicing type (pre-paid/post-paid), + and combinations of start, next, and end dates. + + Main focuses: + - Monthly and monthly-last-day recurrences + - Pre-paid and post-paid contracts + - Edge cases like partial months, contract terminations, or prorations over + irregular dates + """ + + @classmethod + def setUpClass(cls): + super().setUpClass() + # Create partner and product instead of using references that may not exist + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + "email": "test.partner@example.com", + } + ) + cls.product = cls.env["product.product"].create( + { + "name": "Test Service", + "type": "service", + } + ) + cls.contract = cls.env["contract.contract"].create( + [ + { + "name": "Test Contract 2", + "partner_id": cls.partner.id, + "pricelist_id": cls.partner.property_product_pricelist.id, + "contract_type": "purchase", + "contract_line_ids": [ + Command.create( + { + "product_id": cls.product.id, + "name": "Services from #START# to #END#", + "quantity": 1, + "uom_id": cls.product.uom_id.id, + "price_unit": 100, + "discount": 50, + "recurring_rule_type": "monthly", + "recurring_interval": 1, + "date_start": "2016-02-15", + "recurring_next_date": "2016-02-29", + }, + ) + ], + } + ] + ) + cls.contract_line = cls.contract.contract_line_ids[0] + + def _prepare_contract_line( + self, + recurring_rule_type, + recurring_interval, + recurring_invoicing_type, + date_start, + recurring_next_date, + date_end, + last_date_invoiced=False, + ): + """ + Update the existing contract line with the provided configuration. + """ + self.contract_line.write( + { + "recurring_rule_type": recurring_rule_type, + "recurring_invoicing_type": recurring_invoicing_type, + "recurring_interval": recurring_interval, + "date_start": date_start, + "recurring_next_date": recurring_next_date, + "date_end": date_end, + "last_date_invoiced": last_date_invoiced, + } + ) + + def _assert_prorated(self, expected_result): + """ + Assert that the computed prorated invoice value matches the expected result + within 2 decimals. + """ + dates = self.contract_line._get_period_to_invoice( + self.contract_line.last_date_invoiced, + self.contract_line.recurring_next_date, + ) + self.assertAlmostEqual( + expected_result, + self.contract_line.compute_prorated(*dates), + places=2, + ) + + # ---- Test cases ---- + + def test_prorated_case_1(self): + """Pre-paid full period (same day start and next date).""" + self._prepare_contract_line( + "monthly", 1, "pre-paid", "2018-01-05", "2018-01-05", False + ) + self._assert_prorated(1.00) + + def test_prorated_case_2(self): + """Pre-paid, monthly recurrence within January (full month).""" + self._prepare_contract_line( + "monthly", 1, "pre-paid", "2018-01-05", "2018-02-01", False, "2018-01-31" + ) + self._assert_prorated(1.00) + + def test_prorated_case_3(self): + """Pre-paid full month, start from previous year.""" + self._prepare_contract_line( + "monthly", + 1, + "pre-paid", + "2017-01-05", + "2018-02-01", + "2018-03-01", + "2018-01-31", + ) + self._assert_prorated(1.00) + + def test_prorated_case_4(self): + """Pre-paid, partial last month before early termination.""" + self._prepare_contract_line( + "monthly", + 1, + "pre-paid", + "2017-01-05", + "2018-02-01", + "2018-02-25", + "2018-01-31", + ) + self._assert_prorated(0.892) + + def test_prorated_case_5(self): + """Post-paid, full monthly period.""" + self._prepare_contract_line( + "monthly", 1, "post-paid", "2018-01-05", "2018-02-05", False + ) + self._assert_prorated(1.00) + + def test_prorated_case_6(self): + """Post-paid, partial February period.""" + self._prepare_contract_line( + "monthly", 1, "post-paid", "2018-01-05", "2018-02-01", False + ) + self._assert_prorated(0.87) + + def test_prorated_case_7(self): + """Post-paid, full year to next February.""" + self._prepare_contract_line( + "monthly", + 1, + "post-paid", + "2017-01-05", + "2018-02-01", + "2018-03-01", + "2017-12-31", + ) + self._assert_prorated(1.00) + + def test_prorated_case_8(self): + """Post-paid, partial February coverage.""" + self._prepare_contract_line( + "monthly", + 1, + "post-paid", + "2017-01-05", + "2018-03-01", + "2018-02-25", + "2018-01-31", + ) + self._assert_prorated(0.892) + + def test_prorated_case_9(self): + """Post-paid, monthlylastday, full month.""" + self._prepare_contract_line( + "monthlylastday", 1, "post-paid", "2018-01-01", "2018-01-31", "2018-02-25" + ) + self._assert_prorated(1.00) + + def test_prorated_case_10(self): + """Post-paid, monthlylastday, partial month after 5th.""" + self._prepare_contract_line( + "monthlylastday", 1, "post-paid", "2018-01-05", "2018-01-31", "2018-02-25" + ) + self._assert_prorated(0.87) + + def test_prorated_case_11(self): + """Post-paid, monthlylastday, February with partial invoicing.""" + self._prepare_contract_line( + "monthlylastday", + 1, + "post-paid", + "2018-01-05", + "2018-02-28", + "2018-02-25", + "2018-01-31", + ) + self._assert_prorated(0.892) + + def test_prorated_case_12(self): + """Post-paid, February month split exactly in half.""" + self._prepare_contract_line( + "monthlylastday", 1, "post-paid", "2018-02-01", "2018-02-28", "2018-02-14" + ) + self._assert_prorated(0.5) + + def test_prorated_case_13(self): + """Post-paid, second half of February only.""" + self._prepare_contract_line( + "monthlylastday", 1, "post-paid", "2018-02-15", "2018-02-28", False + ) + self._assert_prorated(0.5) + + def test_prorated_case_14(self): + """Post-paid, very small fraction for one day in January.""" + self._prepare_contract_line( + "monthlylastday", + 1, + "post-paid", + "2017-02-15", + "2018-01-31", + False, + "2018-01-30", + ) + self._assert_prorated(0.032) + + def test_prorated_case_15(self): + """Post-paid, over month boundary with slight overrun.""" + self._prepare_contract_line( + "monthlylastday", + 1, + "post-paid", + "2017-02-15", + "2018-02-28", + False, + "2018-01-30", + ) + self._assert_prorated(1.035) + + def test_prorated_case_16(self): + """Post-paid, non-month-end recurrence, tiny fraction.""" + self._prepare_contract_line( + "monthly", 1, "post-paid", "2017-02-15", "2018-02-01", False, "2018-01-30" + ) + self._assert_prorated(0.032) + + def test_prorated_case_17(self): + """Post-paid, larger prorate because of two months in span.""" + self._prepare_contract_line( + "monthly", 1, "post-paid", "2017-02-15", "2018-03-01", False, "2018-01-30" + ) + self._assert_prorated(1.035) + + def test_prorated_case_18(self): + """Pre-paid, clean full month invoicing.""" + self._prepare_contract_line( + "monthly", 1, "pre-paid", "2017-02-15", "2018-01-01", False, "2017-12-31" + ) + self._assert_prorated(1.0) + + def test_prorated_case_19(self): + """Pre-paid, slight overrun from year-end to February.""" + self._prepare_contract_line( + "monthly", 1, "pre-paid", "2017-02-15", "2018-02-01", False, "2018-01-30" + ) + self._assert_prorated(1.035) + + def test_prorated_case_20(self): + """Pre-paid, monthlylastday spanning mid-March.""" + self._prepare_contract_line( + "monthlylastday", 1, "pre-paid", "2018-03-15", "2018-04-30", False + ) + self._assert_prorated(1.566) + + def test_prorated_case_21(self): + """Post-paid, large prorate end of March to April.""" + self._prepare_contract_line( + "monthly", 1, "post-paid", "2018-03-15", "2018-04-30", False + ) + self._assert_prorated(1.48) + + def test_prorated_case_22(self): + """Pre-paid, large prorate mid-March to April.""" + self._prepare_contract_line( + "monthly", 1, "pre-paid", "2018-03-15", "2018-04-30", False + ) + self._assert_prorated(2.53) + + def test_prorated_case_23(self): + """Pre-paid, monthlylastday, full month starting from March 1.""" + self._prepare_contract_line( + "monthlylastday", 1, "pre-paid", "2018-03-01", "2018-03-01", False + ) + self._assert_prorated(1.0) + + def test_prorated_case_24(self): + """Pre-paid, monthlylastday, half-month mid-April start.""" + self._prepare_contract_line( + "monthlylastday", 1, "pre-paid", "2018-04-16", "2018-04-16", False + ) + self._assert_prorated(0.5) diff --git a/contract_variable_qty_prorated/views/contract_template_line.xml b/contract_variable_qty_prorated/views/contract_template_line.xml new file mode 100644 index 0000000000..9fe9b6500c --- /dev/null +++ b/contract_variable_qty_prorated/views/contract_template_line.xml @@ -0,0 +1,17 @@ + + + + + contract.template.line + + + + + True + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..e3d8b66b7f --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-contract @ git+https://github.com/OCA/contract@refs/pull/1312/head#subdirectory=contract +odoo-addon-contract_variable_quantity @ git+https://github.com/OCA/contract@refs/pull/1364/head#subdirectory=contract_variable_quantity