diff --git a/contract_variable_qty_prorated/README.rst b/contract_variable_qty_prorated/README.rst new file mode 100644 index 00000000..9b2ee60e --- /dev/null +++ b/contract_variable_qty_prorated/README.rst @@ -0,0 +1,89 @@ +============================== +Contract Variable Qty Prorated +============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/12.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-12-0/contract-12-0-contract_variable_qty_prorated + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/110/12.0 + :alt: Try me on Runbot + +|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 smashing 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 00000000..0ee8b507 --- /dev/null +++ b/contract_variable_qty_prorated/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/contract_variable_qty_prorated/__manifest__.py b/contract_variable_qty_prorated/__manifest__.py new file mode 100644 index 00000000..fae0e3f6 --- /dev/null +++ b/contract_variable_qty_prorated/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Variable Qty Prorated", + "summary": """ + This module adds a formula to compute prorated quantity to invoice as + extension of the module contract_variable_quantity""", + "version": "12.0.1.0.0", + "development_status": "Beta", + "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/abstract_contract_view.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 00000000..01e34899 --- /dev/null +++ b/contract_variable_qty_prorated/data/contract_variable_qty_prorated.xml @@ -0,0 +1,16 @@ + + + + + + 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 00000000..77c48adc --- /dev/null +++ b/contract_variable_qty_prorated/i18n/contract_variable_qty_prorated.pot @@ -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" +"POT-Creation-Date: 2019-10-01 09:32+0000\n" +"PO-Revision-Date: 2019-10-01 09:32+0000\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 00000000..7c3693d2 --- /dev/null +++ b/contract_variable_qty_prorated/i18n/fr.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" +"POT-Creation-Date: 2019-10-01 09:33+0000\n" +"PO-Revision-Date: 2019-10-01 09:33+0000\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 "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é prorata" + diff --git a/contract_variable_qty_prorated/models/__init__.py b/contract_variable_qty_prorated/models/__init__.py new file mode 100644 index 00000000..6143a365 --- /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 00000000..91605c50 --- /dev/null +++ b/contract_variable_qty_prorated/models/contract_line.py @@ -0,0 +1,45 @@ +# 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" + + @api.model + def _compute_prorated( + self, real_next_date, real_last_date, therical_next_date, + therical_last_date): + def _invoiced_days(next_date, last_date): + return (next_date - last_date).days + 1 + + return _invoiced_days(real_next_date, real_last_date) / _invoiced_days( + therical_next_date, therical_last_date + ) + + @api.multi + def compute_prorated(self, period_first_date, period_last_date, + invoice_date): + self.ensure_one() + relative_delta = self.get_relative_delta( + self.recurring_rule_type, self.recurring_interval + ) + theoretical_next_date = invoice_date + if self.recurring_rule_type == "monthlylastday": + relative_delta = self.get_relative_delta("monthly", + self.recurring_interval) + theoretical_next_date += self.get_relative_delta("daily", 1) + if ( + self.recurring_invoicing_type == "pre-paid" + and self.recurring_rule_type != "monthlylastday" + ): + 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 self._compute_prorated( + real_next_date, real_last_date, theoretical_next_date, + theoretical_last_date + ) diff --git a/contract_variable_qty_prorated/readme/CONTRIBUTORS.rst b/contract_variable_qty_prorated/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..724261d7 --- /dev/null +++ b/contract_variable_qty_prorated/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Souheil Bejaoui +* Thomas Binsfeld diff --git a/contract_variable_qty_prorated/readme/DESCRIPTION.rst b/contract_variable_qty_prorated/readme/DESCRIPTION.rst new file mode 100644 index 00000000..3877b5d9 --- /dev/null +++ b/contract_variable_qty_prorated/readme/DESCRIPTION.rst @@ -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.rst b/contract_variable_qty_prorated/readme/ROADMAP.rst new file mode 100644 index 00000000..33bec5c8 --- /dev/null +++ b/contract_variable_qty_prorated/readme/ROADMAP.rst @@ -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/index.html b/contract_variable_qty_prorated/static/description/index.html new file mode 100644 index 00000000..20b1a7e1 --- /dev/null +++ b/contract_variable_qty_prorated/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Contract Variable Qty Prorated + + + +
+

Contract Variable Qty Prorated

+ + +

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

+

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 smashing 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 00000000..2b7f5ecf --- /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 00000000..7fd610c1 --- /dev/null +++ b/contract_variable_qty_prorated/tests/test_compute_proprata.py @@ -0,0 +1,395 @@ +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields +from odoo.tests.common import TransactionCase + + +def to_date(date): + return fields.Date.to_date(date) + + +class TestProductTemplate(TransactionCase): + def setUp(self): + super(TestProductTemplate, self).setUp() + self.partner = self.env.ref("base.res_partner_2") + self.product = self.env.ref("product.product_product_1") + self.contract = self.env["contract.contract"].create( + { + "name": "Test Contract 2", + "partner_id": self.partner.id, + "pricelist_id": self.partner.property_product_pricelist.id, + "contract_type": "purchase", + "contract_line_ids": [ + ( + 0, + 0, + { + "product_id": self.product.id, + "name": "Services from #START# to #END#", + "quantity": 1, + "uom_id": self.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", + }, + ) + ], + } + ) + self.contract_line = self.contract.contract_line_ids[0] + + def test_compute_prorated(self): + def update_contract_line( + case, + recurring_rule_type, + recurring_interval, + recurring_invoicing_type, + date_start, + recurring_next_date, + date_end, + last_date_invoiced=False, + ): + 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 error_message( + case, + recurring_rule_type, + recurring_interval, + recurring_invoicing_type, + date_start, + recurring_next_date, + date_end, + last_date_invoiced=False, + ): + return ( + "%s : Error in %s every %d %s case, start %s, next %s, end %s," + " last %s" + % ( + case, + recurring_invoicing_type, + recurring_interval, + recurring_rule_type, + date_start, + recurring_next_date, + date_end, + last_date_invoiced or "", + ) + ) + + combinations = [ + ( + 1.00, + ( + "Case 1", + "monthly", + 1, + "pre-paid", + to_date("2018-01-05"), + to_date("2018-01-05"), + False, + ), + ), + ( + 1.00, + ( + "Case 2", + "monthly", + 1, + "pre-paid", + to_date("2018-01-05"), + to_date("2018-02-01"), + False, + to_date("2018-01-31"), + ), + ), + ( + 1.00, + ( + "Case 3", + "monthly", + 1, + "pre-paid", + to_date("2017-01-05"), + to_date("2018-02-01"), + to_date("2018-03-01"), + to_date("2018-01-31"), + ), + ), + ( + 0.892, + ( + "Case 4", + "monthly", + 1, + "pre-paid", + to_date("2017-01-05"), + to_date("2018-02-01"), + to_date("2018-02-25"), + to_date("2018-01-31"), + ), + ), + ( + 1.00, + ( + "Case 5", + "monthly", + 1, + "post-paid", + to_date("2018-01-05"), + to_date("2018-02-05"), + False, + ), + ), + ( + 0.87, + ( + "Case 6", + "monthly", + 1, + "post-paid", + to_date("2018-01-05"), + to_date("2018-02-01"), + False, + ), + ), + ( + 1.00, + ( + "Case 7", + "monthly", + 1, + "post-paid", + to_date("2017-01-05"), + to_date("2018-02-01"), + to_date("2018-03-01"), + to_date("2017-12-31"), + ), + ), + ( + 0.892, + ( + "Case 8", + "monthly", + 1, + "post-paid", + to_date("2017-01-05"), + to_date("2018-03-01"), + to_date("2018-02-25"), + to_date("2018-01-31"), + ), + ), + ( + 1.00, + ( + "Case 9", + "monthlylastday", + 1, + "post-paid", + to_date("2018-01-01"), + to_date("2018-01-31"), + to_date("2018-02-25"), + ), + ), + ( + 0.87, + ( + "Case 10", + "monthlylastday", + 1, + "post-paid", + to_date("2018-01-05"), + to_date("2018-01-31"), + to_date("2018-02-25"), + ), + ), + ( + 0.892, + ( + "Case 11", + "monthlylastday", + 1, + "post-paid", + to_date("2018-01-05"), + to_date("2018-02-28"), + to_date("2018-02-25"), + to_date("2018-01-31"), + ), + ), + ( + 0.5, + ( + "Case 12", + "monthlylastday", + 1, + "post-paid", + to_date("2018-02-01"), + to_date("2018-02-28"), + to_date("2018-02-14"), + ), + ), + ( + 0.5, + ( + "Case 13", + "monthlylastday", + 1, + "post-paid", + to_date("2018-02-15"), + to_date("2018-02-28"), + False, + ), + ), + ( + 0.032, + ( + "Case 14", + "monthlylastday", + 1, + "post-paid", + to_date("2017-02-15"), + to_date("2018-01-31"), + False, + to_date("2018-01-30"), + ), + ), + ( + 1.035, + ( + "Case 15", + "monthlylastday", + 1, + "post-paid", + to_date("2017-02-15"), + to_date("2018-02-28"), + False, + to_date("2018-01-30"), + ), + ), + ( + 0.032, + ( + "Case 16", + "monthly", + 1, + "post-paid", + to_date("2017-02-15"), + to_date("2018-02-01"), + False, + to_date("2018-01-30"), + ), + ), + ( + 1.035, + ( + "Case 17", + "monthly", + 1, + "post-paid", + to_date("2017-02-15"), + to_date("2018-03-01"), + False, + to_date("2018-01-30"), + ), + ), + ( + 0.032, + ( + "Case 18", + "monthly", + 1, + "pre-paid", + to_date("2017-02-15"), + to_date("2018-01-01"), + False, + to_date("2018-01-30"), + ), + ), + ( + 1.035, + ( + "Case 19", + "monthly", + 1, + "pre-paid", + to_date("2017-02-15"), + to_date("2018-02-01"), + False, + to_date("2018-01-30"), + ), + ), + ( + 1.0, + ( + "Case 18", + "monthlylastday", + 1, + "pre-paid", + to_date("2017-02-15"), + to_date("2018-01-31"), + False, + to_date("2017-12-31"), + ), + ), + ( + 1.566, + ( + "Case 19", + "monthlylastday", + 1, + "pre-paid", + to_date("2018-03-15"), + to_date("2018-04-30"), + False, + ), + ), + ( + 1.48, + ( + "Case 20", + "monthly", + 1, + "post-paid", + to_date("2018-03-15"), + to_date("2018-04-30"), + False, + ), + ), + ( + 2.53, + ( + "Case 21", + "monthly", + 1, + "pre-paid", + to_date("2018-03-15"), + to_date("2018-04-30"), + False, + ), + ), + ] + for result, combination in combinations: + update_contract_line(*combination) + dates = self.contract_line._get_period_to_invoice( + self.contract_line.last_date_invoiced, + self.contract_line.recurring_next_date, + ) + self.assertAlmostEqual( + result, + self.contract_line.compute_prorated(*dates), + places=2, + msg=error_message(*combination), + ) diff --git a/contract_variable_qty_prorated/views/abstract_contract_view.xml b/contract_variable_qty_prorated/views/abstract_contract_view.xml new file mode 100644 index 00000000..3a4e3b61 --- /dev/null +++ b/contract_variable_qty_prorated/views/abstract_contract_view.xml @@ -0,0 +1,22 @@ + + + + + + + + Contract Line Form View (in abstract_contract_view.xml) + contract.abstract.contract.line + + + + + True + + + + +