diff --git a/sale_multi_template_application/README.rst b/sale_multi_template_application/README.rst new file mode 100644 index 00000000000..d910238de82 --- /dev/null +++ b/sale_multi_template_application/README.rst @@ -0,0 +1,102 @@ +=============================== +Sale multi template application +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3439323a6c943bdba07b62a2ce3eafdc3af3503f214f42b0ad99d2d601bb36bb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/18.0/sale_multi_template_application + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_multi_template_application + :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/sale-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows multiple templates to be applied to the same sales +order, keeping the existing order lines without deleting the previous +ones. + +For consistency, the template field is emptied for not keeping the order +linked to a possible partial template. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +- Go to *Sales > Configuration > Quotation Templates*. +- Create at least two quotation templates and add some lines to each + template. + +Usage +===== + +- Go to *Sales > Orders > Quotations*. +- Create a new sales order. +- Select the first quotation template. +- Select the second quotation template, and the order lines from the + first template are retained. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Pedro M. Baeza + - Carlos López + +- Heliconia Solutions Pvt. Ltd. https://www.heliconia.io + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_multi_template_application/__init__.py b/sale_multi_template_application/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_multi_template_application/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_multi_template_application/__manifest__.py b/sale_multi_template_application/__manifest__.py new file mode 100644 index 00000000000..2c7f79cb089 --- /dev/null +++ b/sale_multi_template_application/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Sale multi template application", + "version": "18.0.1.0.0", + "author": "Tecnativa,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "category": "Sales", + "depends": [ + "sale_management", + ], + "installable": True, + "license": "AGPL-3", +} diff --git a/sale_multi_template_application/i18n/it.po b/sale_multi_template_application/i18n/it.po new file mode 100644 index 00000000000..953dc981ded --- /dev/null +++ b/sale_multi_template_application/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_multi_template_application +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-12-20 18:06+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.6.2\n" + +#. module: sale_multi_template_application +#: model:ir.model,name:sale_multi_template_application.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" diff --git a/sale_multi_template_application/i18n/sale_multi_template_application.pot b/sale_multi_template_application/i18n/sale_multi_template_application.pot new file mode 100644 index 00000000000..24c272bfcbd --- /dev/null +++ b/sale_multi_template_application/i18n/sale_multi_template_application.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_multi_template_application +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: sale_multi_template_application +#: model:ir.model,name:sale_multi_template_application.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/sale_multi_template_application/models/__init__.py b/sale_multi_template_application/models/__init__.py new file mode 100644 index 00000000000..6aacb753131 --- /dev/null +++ b/sale_multi_template_application/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_multi_template_application/models/sale_order.py b/sale_multi_template_application/models/sale_order.py new file mode 100644 index 00000000000..18e8e2376f8 --- /dev/null +++ b/sale_multi_template_application/models/sale_order.py @@ -0,0 +1,25 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.onchange("sale_order_template_id") + def _onchange_sale_order_template_id(self): + # We need to keep the old lines, to restore them after the template change + current_lines = self.order_line + # We need to keep the max sequence + # of the lines when changing the template + # because odoo set the sequence for the first line to -99 + max_sequence = max(current_lines.mapped("sequence"), default=10) + res = super()._onchange_sale_order_template_id() + for line in self.order_line: + sequence = 10 if line.sequence == -99 else line.sequence + line.sequence = sequence + max_sequence + self.order_line += current_lines + self.sale_order_template_id = False + return res diff --git a/sale_multi_template_application/pyproject.toml b/sale_multi_template_application/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_multi_template_application/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_multi_template_application/readme/CONFIGURE.md b/sale_multi_template_application/readme/CONFIGURE.md new file mode 100644 index 00000000000..004f1d34559 --- /dev/null +++ b/sale_multi_template_application/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +- Go to *Sales \> Configuration \> Quotation Templates*. +- Create at least two quotation templates and add some lines to each template. + diff --git a/sale_multi_template_application/readme/CONTRIBUTORS.md b/sale_multi_template_application/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..fa4bf765443 --- /dev/null +++ b/sale_multi_template_application/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pedro M. Baeza + - Carlos López +- Heliconia Solutions Pvt. Ltd. diff --git a/sale_multi_template_application/readme/DESCRIPTION.md b/sale_multi_template_application/readme/DESCRIPTION.md new file mode 100644 index 00000000000..04a8c0669b3 --- /dev/null +++ b/sale_multi_template_application/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows multiple templates to be applied to the same sales order, keeping the existing order lines without deleting the previous ones. + +For consistency, the template field is emptied for not keeping the order linked to a possible partial template. \ No newline at end of file diff --git a/sale_multi_template_application/readme/USAGE.md b/sale_multi_template_application/readme/USAGE.md new file mode 100644 index 00000000000..81ed989334b --- /dev/null +++ b/sale_multi_template_application/readme/USAGE.md @@ -0,0 +1,4 @@ +- Go to *Sales \> Orders \> Quotations*. +- Create a new sales order. +- Select the first quotation template. +- Select the second quotation template, and the order lines from the first template are retained. diff --git a/sale_multi_template_application/static/description/icon.png b/sale_multi_template_application/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_multi_template_application/static/description/icon.png differ diff --git a/sale_multi_template_application/static/description/index.html b/sale_multi_template_application/static/description/index.html new file mode 100644 index 00000000000..bafa97c5bb7 --- /dev/null +++ b/sale_multi_template_application/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Sale multi template application + + + +
+

Sale multi template application

+ + +

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

+

This module allows multiple templates to be applied to the same sales +order, keeping the existing order lines without deleting the previous +ones.

+

For consistency, the template field is emptied for not keeping the order +linked to a possible partial template.

+

Table of contents

+ +
+

Configuration

+
    +
  • Go to Sales > Configuration > Quotation Templates.
  • +
  • Create at least two quotation templates and add some lines to each +template.
  • +
+
+
+

Usage

+
    +
  • Go to Sales > Orders > Quotations.
  • +
  • Create a new sales order.
  • +
  • Select the first quotation template.
  • +
  • Select the second quotation template, and the order lines from the +first template are retained.
  • +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_multi_template_application/tests/__init__.py b/sale_multi_template_application/tests/__init__.py new file mode 100644 index 00000000000..3c6311b7ce9 --- /dev/null +++ b/sale_multi_template_application/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_multi_template_application diff --git a/sale_multi_template_application/tests/test_sale_multi_template_application.py b/sale_multi_template_application/tests/test_sale_multi_template_application.py new file mode 100644 index 00000000000..442507f8b90 --- /dev/null +++ b/sale_multi_template_application/tests/test_sale_multi_template_application.py @@ -0,0 +1,54 @@ +# Copyright 2024 Tecnativa - Carlos López +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo.tests import Form + +from odoo.addons.base.tests.common import BaseCommon + + +class TestProductTaskRecurrency(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.Product = cls.env["product.product"] + cls.SaleTemplate = cls.env["sale.order.template"] + cls.product_1 = cls.Product.create({"name": "Product 1"}) + cls.product_2 = cls.Product.create({"name": "Product 2"}) + cls.product_3 = cls.Product.create({"name": "Product 3"}) + cls.sale_template_1 = cls.SaleTemplate.create( + { + "name": "Template", + "sale_order_template_line_ids": [ + (0, 0, {"product_id": cls.product_1.id, "sequence": 20}), + (0, 0, {"product_id": cls.product_2.id, "sequence": 30}), + ], + } + ) + cls.sale_template_2 = cls.SaleTemplate.create( + { + "name": "Template", + "sale_order_template_line_ids": [ + (0, 0, {"product_id": cls.product_3.id, "sequence": 40}) + ], + } + ) + + def test_sale_order_template(self): + with Form(self.env["sale.order"]) as sale_order_form: + sale_order_form.partner_id = self.partner + sale_order_form.sale_order_template_id = self.sale_template_1 + self.assertEqual(len(sale_order_form.order_line), 2) + self.assertFalse(sale_order_form.sale_order_template_id) + sale_order_form.sale_order_template_id = self.sale_template_2 + self.assertEqual(len(sale_order_form.order_line), 3) + self.assertFalse(sale_order_form.sale_order_template_id) + sale_order = sale_order_form.save() + self.assertEqual(sale_order.order_line[0].sequence, 20) + self.assertEqual(sale_order.order_line[0].product_id, self.product_1) + self.assertEqual(sale_order.order_line[1].sequence, 40) + self.assertEqual(sale_order.order_line[1].product_id, self.product_2) + # the sequence is -99 because it is the first line in the second template + # so, reset the sequence to 10 + max_sequence(40) = 50 + self.assertEqual(sale_order.order_line[2].sequence, 50) + self.assertEqual(sale_order.order_line[2].product_id, self.product_3)