diff --git a/product_contract_variable_quantity/README.rst b/product_contract_variable_quantity/README.rst new file mode 100644 index 0000000000..50d1e3022b --- /dev/null +++ b/product_contract_variable_quantity/README.rst @@ -0,0 +1,77 @@ +================================== +Product Contract Variable Quantity +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9d3e841cf1aa3507deb9b0cc7a1acad44748585954d00d33e423a6c48db4a798 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_variable_quantity + :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_variable_quantity + :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 add default values to contract products for variable +quantity formula. + +**Table of contents** + +.. contents:: + :local: + +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 + +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_variable_quantity/__init__.py b/product_contract_variable_quantity/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/product_contract_variable_quantity/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_contract_variable_quantity/__manifest__.py b/product_contract_variable_quantity/__manifest__.py new file mode 100644 index 0000000000..ce6c3c0e63 --- /dev/null +++ b/product_contract_variable_quantity/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Product Contract Variable Quantity", + "summary": """ + Product contract with variable quantity""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/contract", + "depends": ["contract_variable_quantity", "product_contract"], + "data": [ + "views/product_template.xml", + "views/sale_order.xml", + "wizards/product_contract_configurator.xml", + ], + "demo": [], +} diff --git a/product_contract_variable_quantity/i18n/fr.po b/product_contract_variable_quantity/i18n/fr.po new file mode 100644 index 0000000000..a28c8cb7c7 --- /dev/null +++ b/product_contract_variable_quantity/i18n/fr.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract_variable_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-01-04 11:44+0000\n" +"Last-Translator: Rémi \n" +"Language-Team: none\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: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_contract_line +msgid "Contract Line" +msgstr "Ligne de Contrat" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Fixed quantity" +msgstr "Quantité fixe" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_product_template +msgid "Product Template" +msgstr "Modèle d'article" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_formula_id +msgid "Qty. formula" +msgstr "Formule de Quantité" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_type +msgid "Qty. type" +msgstr "Type de quantité" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne de commande" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Variable quantity" +msgstr "Quantité variable" diff --git a/product_contract_variable_quantity/i18n/it.po b/product_contract_variable_quantity/i18n/it.po new file mode 100644 index 0000000000..2b8e367deb --- /dev/null +++ b/product_contract_variable_quantity/i18n/it.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract_variable_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-10-29 17:40+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 4.17\n" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_contract_line +msgid "Contract Line" +msgstr "Riga di contratto" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Fixed quantity" +msgstr "Quantità fissa" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_product_template +msgid "Product Template" +msgstr "Modello prodotto" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_formula_id +msgid "Qty. formula" +msgstr "Q.tà formula" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_type +msgid "Qty. type" +msgstr "Q.tà tipo" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Variable quantity" +msgstr "Quantità variabile" diff --git a/product_contract_variable_quantity/i18n/product_contract_variable_quantity.pot b/product_contract_variable_quantity/i18n/product_contract_variable_quantity.pot new file mode 100644 index 0000000000..12ef817ce0 --- /dev/null +++ b/product_contract_variable_quantity/i18n/product_contract_variable_quantity.pot @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract_variable_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_contract_line +msgid "Contract Line" +msgstr "" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 +#: selection:sale.order.line,qty_type:0 +msgid "Fixed quantity" +msgstr "" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_formula_id +msgid "Qty. formula" +msgstr "" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_type +msgid "Qty. type" +msgstr "" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 +#: selection:sale.order.line,qty_type:0 +msgid "Variable quantity" +msgstr "" + diff --git a/product_contract_variable_quantity/i18n/pt.po b/product_contract_variable_quantity/i18n/pt.po new file mode 100644 index 0000000000..df0c7e874f --- /dev/null +++ b/product_contract_variable_quantity/i18n/pt.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract_variable_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-03-01 18:13+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\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: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_contract_line +msgid "Contract Line" +msgstr "Linha de Contrato" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Fixed quantity" +msgstr "Quantidade fixa" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_product_template +msgid "Product Template" +msgstr "Modelo de Artigo" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_formula_id +msgid "Qty. formula" +msgstr "Fórmula de Qtd" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_type +msgid "Qty. type" +msgstr "Tipo de Qtd." + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_sale_order_line +msgid "Sales Order Line" +msgstr "Linha de Encomenda de Venda" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Variable quantity" +msgstr "Quantidade variável" diff --git a/product_contract_variable_quantity/i18n/pt_BR.po b/product_contract_variable_quantity/i18n/pt_BR.po new file mode 100644 index 0000000000..86a1ba76d7 --- /dev/null +++ b/product_contract_variable_quantity/i18n/pt_BR.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract_variable_quantity +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2020-08-10 16:59+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: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_contract_line +msgid "Contract Line" +msgstr "Linha de Contrato" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Fixed quantity" +msgstr "Quantidade Fixa" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_product_template +msgid "Product Template" +msgstr "Modelo de Produto" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_formula_id +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_formula_id +msgid "Qty. formula" +msgstr "Fórmula da Quantidade" + +#. module: product_contract_variable_quantity +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_product__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_product_template__qty_type +#: model:ir.model.fields,field_description:product_contract_variable_quantity.field_sale_order_line__qty_type +msgid "Qty. type" +msgstr "Tipo de Quantidade" + +#. module: product_contract_variable_quantity +#: model:ir.model,name:product_contract_variable_quantity.model_sale_order_line +msgid "Sales Order Line" +msgstr "Linha do Pedido de Venda" + +#. module: product_contract_variable_quantity +#: selection:product.template,qty_type:0 selection:sale.order.line,qty_type:0 +msgid "Variable quantity" +msgstr "Quantidade Variável" diff --git a/product_contract_variable_quantity/models/__init__.py b/product_contract_variable_quantity/models/__init__.py new file mode 100644 index 0000000000..0681fc2e85 --- /dev/null +++ b/product_contract_variable_quantity/models/__init__.py @@ -0,0 +1,7 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import contract_line +from . import product_template +from . import sale_order_line +from . import sale_order_line_contract_mixin diff --git a/product_contract_variable_quantity/models/contract_line.py b/product_contract_variable_quantity/models/contract_line.py new file mode 100644 index 0000000000..1b8db85aae --- /dev/null +++ b/product_contract_variable_quantity/models/contract_line.py @@ -0,0 +1,17 @@ +# Copyright 2017 LasLabs Inc. +# 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.onchange("product_id") + def _onchange_product_id_recurring_info(self): + res = super()._onchange_product_id_recurring_info() + if self.product_id.is_contract: + self.qty_type = self.product_id.qty_type + self.qty_formula_id = self.product_id.qty_formula_id + return res diff --git a/product_contract_variable_quantity/models/product_template.py b/product_contract_variable_quantity/models/product_template.py new file mode 100644 index 0000000000..05dea59d63 --- /dev/null +++ b/product_contract_variable_quantity/models/product_template.py @@ -0,0 +1,21 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + qty_type = fields.Selection( + selection=[ + ("fixed", "Fixed quantity"), + ("variable", "Variable quantity"), + ], + required=False, + default="fixed", + string="Qty. type", + ) + qty_formula_id = fields.Many2one( + comodel_name="contract.line.qty.formula", string="Qty. formula" + ) diff --git a/product_contract_variable_quantity/models/sale_order_line.py b/product_contract_variable_quantity/models/sale_order_line.py new file mode 100644 index 0000000000..e91085ee13 --- /dev/null +++ b/product_contract_variable_quantity/models/sale_order_line.py @@ -0,0 +1,17 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2017 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _prepare_contract_line_values(self, contract, predecessor_contract_line=False): + values = super()._prepare_contract_line_values( + contract, predecessor_contract_line + ) + values["qty_type"] = self.qty_type + values["qty_formula_id"] = self.qty_formula_id.id + return values diff --git a/product_contract_variable_quantity/models/sale_order_line_contract_mixin.py b/product_contract_variable_quantity/models/sale_order_line_contract_mixin.py new file mode 100644 index 0000000000..4d6acb16a9 --- /dev/null +++ b/product_contract_variable_quantity/models/sale_order_line_contract_mixin.py @@ -0,0 +1,42 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class SaleOrderLineContractMixin(models.AbstractModel): + _inherit = "sale.order.line.contract.mixin" + + qty_type = fields.Selection( + selection=[ + ("fixed", "Fixed quantity"), + ("variable", "Variable quantity"), + ], + required=False, + default="fixed", + string="Qty. type", + compute="_compute_product_contract_data", + precompute=True, + store=True, + readonly=False, + ) + qty_formula_id = fields.Many2one( + comodel_name="contract.line.qty.formula", + string="Qty. formula", + compute="_compute_product_contract_data", + precompute=True, + store=True, + readonly=False, + ) + + @api.depends("product_id") + def _compute_product_contract_data(self): + res = super()._compute_product_contract_data() + for rec in self: + vals = {"qty_type": False, "qty_formula_id": False} + if rec.product_id.is_contract: + p = rec.product_id + vals = {"qty_type": p.qty_type, "qty_formula_id": p.qty_formula_id.id} + rec.update(vals) + return res diff --git a/product_contract_variable_quantity/pyproject.toml b/product_contract_variable_quantity/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/product_contract_variable_quantity/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/product_contract_variable_quantity/readme/CONTRIBUTORS.md b/product_contract_variable_quantity/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..fc5fcbefea --- /dev/null +++ b/product_contract_variable_quantity/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui \<\> diff --git a/product_contract_variable_quantity/readme/DESCRIPTION.md b/product_contract_variable_quantity/readme/DESCRIPTION.md new file mode 100644 index 0000000000..285f125b97 --- /dev/null +++ b/product_contract_variable_quantity/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module add default values to contract products for variable +quantity formula. diff --git a/product_contract_variable_quantity/static/description/icon.png b/product_contract_variable_quantity/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/product_contract_variable_quantity/static/description/icon.png differ diff --git a/product_contract_variable_quantity/static/description/index.html b/product_contract_variable_quantity/static/description/index.html new file mode 100644 index 0000000000..409b48671d --- /dev/null +++ b/product_contract_variable_quantity/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Product Contract Variable Quantity + + + +
+

Product Contract Variable Quantity

+ + +

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

+

This module add default values to contract products for variable +quantity formula.

+

Table of contents

+ +
+

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_variable_quantity/tests/__init__.py b/product_contract_variable_quantity/tests/__init__.py new file mode 100644 index 0000000000..b5d241da0f --- /dev/null +++ b/product_contract_variable_quantity/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_sale_order diff --git a/product_contract_variable_quantity/tests/test_sale_order.py b/product_contract_variable_quantity/tests/test_sale_order.py new file mode 100644 index 0000000000..9033283d10 --- /dev/null +++ b/product_contract_variable_quantity/tests/test_sale_order.py @@ -0,0 +1,65 @@ +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestSaleOrder(TransactionCase): + def setUp(self): + super().setUp() + self.product1 = self.env.ref("product.product_product_1") + self.sale = self.env.ref("sale.sale_order_2") + self.contract_template1 = self.env["contract.template"].create( + {"name": "Template 1"} + ) + self.formula = self.env["contract.line.qty.formula"].create( + { + "name": "Test formula", + # For testing each of the possible variables + "code": 'env["res.users"]\n' + 'context.get("lang")\n' + "user.id\n" + "line.qty_type\n" + "contract.id\n" + "invoice.id\n" + "result = 12", + } + ) + self.product1.with_context(force_company=self.sale.company_id.id).write( + { + "is_contract": True, + "default_qty": 12, + "property_contract_template_id": self.contract_template1.id, + "qty_formula_id": self.formula.id, + "qty_type": "variable", + } + ) + self.order_line1 = self.sale.order_line.filtered( + lambda line: line.product_id == self.product1 + ) + + def test_change_is_contract(self): + product_tmpl = self.product1.product_tmpl_id + product_tmpl.is_contract = False + self.assertTrue(product_tmpl.qty_type) + product_tmpl._change_is_contract() + self.assertFalse(product_tmpl.qty_type) + + def test_onchange_product_id(self): + self.order_line1.onchange_product() + self.assertEqual(self.order_line1.qty_formula_id, self.product1.qty_formula_id) + self.assertEqual(self.order_line1.qty_type, self.product1.qty_type) + + def test_action_confirm(self): + self.order_line1.onchange_product() + self.sale.action_confirm() + contract = self.order_line1.contract_id + contract_line = contract.contract_line_ids.filtered( + lambda line: line.product_id == self.product1 + ) + self.assertEqual(contract_line.qty_formula_id, self.product1.qty_formula_id) + self.assertEqual(contract_line.qty_type, self.product1.qty_type) + self.assertEqual(contract_line.qty_type, "variable") + self.product1.product_tmpl_id.qty_type = "fixed" + contract_line._onchange_product_id_recurring_info() + self.assertEqual(contract_line.qty_type, "fixed") diff --git a/product_contract_variable_quantity/views/product_template.xml b/product_contract_variable_quantity/views/product_template.xml new file mode 100644 index 0000000000..e89b8a3f3c --- /dev/null +++ b/product_contract_variable_quantity/views/product_template.xml @@ -0,0 +1,27 @@ + + + + + product.template + + + + + + + + + + + diff --git a/product_contract_variable_quantity/views/sale_order.xml b/product_contract_variable_quantity/views/sale_order.xml new file mode 100644 index 0000000000..f03de3be18 --- /dev/null +++ b/product_contract_variable_quantity/views/sale_order.xml @@ -0,0 +1,20 @@ + + + + + sale.order + + + + + + + + + diff --git a/product_contract_variable_quantity/wizards/product_contract_configurator.xml b/product_contract_variable_quantity/wizards/product_contract_configurator.xml new file mode 100644 index 0000000000..872b2a8b02 --- /dev/null +++ b/product_contract_variable_quantity/wizards/product_contract_configurator.xml @@ -0,0 +1,31 @@ + + + + + product.contract.configurator + + + + + + + + + + qty_type == 'variable' + + + +