diff --git a/sale_exception_product_sale_manufactured_for/README.rst b/sale_exception_product_sale_manufactured_for/README.rst new file mode 100644 index 00000000000..a0be31c4e25 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/README.rst @@ -0,0 +1,92 @@ +================================================ +Sale Exception Product Manufactured for Customer +================================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:085a2fb87bda20031af7ba0a11403b34b0c473e63a33c0f9d6081b99e190defc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_exception_product_sale_manufactured_for + :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_exception_product_sale_manufactured_for + :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| + +The partner set in the sales order can order only if he/she has a +commercial entity that is listed as one of the partners for which the +products can be manufactured for. + +**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 +------- + +* Camptocamp + +Contributors +------------ + +- `Camptocamp `__: + + - Carlos Serra-Toro + - Simone Orsi + - Thierry Ducrest + +- `Trobz `__: + + - Son Ho + - Nhan Tran + +Other credits +------------- + +**Financial support** \* Cosanum \* Camptocamp R&D + +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_exception_product_sale_manufactured_for/__init__.py b/sale_exception_product_sale_manufactured_for/__init__.py new file mode 100644 index 00000000000..d4b7188d6e5 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import models diff --git a/sale_exception_product_sale_manufactured_for/__manifest__.py b/sale_exception_product_sale_manufactured_for/__manifest__.py new file mode 100644 index 00000000000..3e409b93352 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +{ + "name": "Sale Exception Product Manufactured for Customer", + "summary": "The partner set in the sales order can order only if he/she " + "has a commercial entity that is listed as one of the partners " + "for which the products can be manufactured for.", + "version": "18.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/sale-workflow", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "data": [ + "data/exception_rule.xml", + ], + "demo": [ + "demo/exception_rule.xml", + ], + "depends": [ + "sale_exception", + "product_sale_manufactured_for", + ], +} diff --git a/sale_exception_product_sale_manufactured_for/data/exception_rule.xml b/sale_exception_product_sale_manufactured_for/data/exception_rule.xml new file mode 100644 index 00000000000..233f6f943f5 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/data/exception_rule.xml @@ -0,0 +1,15 @@ + + + + Partner can order all the items in the sale + The partner set in the sales order can order only + if he/she has a commercial entity that is listed as one of the partners + for which the products can be manufactured for. + 50 + sale.order + failed = not obj.exception_partner_can_order_manufactured_for() + True + + diff --git a/sale_exception_product_sale_manufactured_for/demo/exception_rule.xml b/sale_exception_product_sale_manufactured_for/demo/exception_rule.xml new file mode 100644 index 00000000000..67a525a5262 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/demo/exception_rule.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/sale_exception_product_sale_manufactured_for/i18n/es.po b/sale_exception_product_sale_manufactured_for/i18n/es.po new file mode 100644 index 00000000000..7b26f4a905a --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/i18n/es.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_product_sale_manufactured_for +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-17 18:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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: sale_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order__display_name +msgid "Display Name" +msgstr "Mostrar Nombre" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order__id +msgid "ID" +msgstr "ID" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order____last_update +msgid "Last Modified on" +msgstr "Última Modificación el" + +#. module: sale_exception_product_sale_manufactured_for +#: model:exception.rule,name:sale_exception_product_sale_manufactured_for.exception_partner_can_order +msgid "Partner can order all the items in the sale" +msgstr "Los socios pueden pedir todos los artículos de la oferta" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model,name:sale_exception_product_sale_manufactured_for.model_sale_order +msgid "Sales Order" +msgstr "Orden de Ventas" + +#. module: sale_exception_product_sale_manufactured_for +#: model:exception.rule,description:sale_exception_product_sale_manufactured_for.exception_partner_can_order +msgid "" +"The partner set in the sales order can order only\n" +" if he/she has a commercial entity that is listed as one of the partners\n" +" for which the products can be manufactured for." +msgstr "" +"El socio establecido en el pedido de venta sólo puede realizar pedidos\n" +" si tiene una entidad comercial que figura como uno de los " +"socios\n" +" para los que se pueden fabricar los productos." diff --git a/sale_exception_product_sale_manufactured_for/i18n/sale_exception_product_sale_manufactured_for.pot b/sale_exception_product_sale_manufactured_for/i18n/sale_exception_product_sale_manufactured_for.pot new file mode 100644 index 00000000000..b522327842b --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/i18n/sale_exception_product_sale_manufactured_for.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_product_sale_manufactured_for +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order__display_name +msgid "Display Name" +msgstr "" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order__id +msgid "ID" +msgstr "" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model.fields,field_description:sale_exception_product_sale_manufactured_for.field_sale_order____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sale_exception_product_sale_manufactured_for +#: model:exception.rule,name:sale_exception_product_sale_manufactured_for.exception_partner_can_order +msgid "Partner can order all the items in the sale" +msgstr "" + +#. module: sale_exception_product_sale_manufactured_for +#: model:ir.model,name:sale_exception_product_sale_manufactured_for.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_exception_product_sale_manufactured_for +#: model:exception.rule,description:sale_exception_product_sale_manufactured_for.exception_partner_can_order +msgid "" +"The partner set in the sales order can order only\n" +" if he/she has a commercial entity that is listed as one of the partners\n" +" for which the products can be manufactured for." +msgstr "" diff --git a/sale_exception_product_sale_manufactured_for/models/__init__.py b/sale_exception_product_sale_manufactured_for/models/__init__.py new file mode 100644 index 00000000000..2ad46d01556 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import sale_order diff --git a/sale_exception_product_sale_manufactured_for/models/sale_order.py b/sale_exception_product_sale_manufactured_for/models/sale_order.py new file mode 100644 index 00000000000..05e5a9bb696 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/models/sale_order.py @@ -0,0 +1,49 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from odoo import models +from odoo.tools import SQL + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def exception_partner_can_order_manufactured_for(self): + """Return whether the partner can order all the items in the sale + + Used in a sales exception. Returns true only if the partner set in + the sales order can buy all the products. This will happen if: + 1. it has a commercial entity that is listed as one of the + partners for which the products can be manufactured for. + 2. it doesn't have a commercial entity and none of the products + on the sale order have any restriction. + """ + self.ensure_one() + commercial_entity = self.partner_id.commercial_partner_id + + self.env.cr.execute( + SQL( + """ + SELECT rel.product_id, ARRAY_AGG(rel.partner_id) + FROM sale_order_line sol + JOIN product_product prod ON (sol.product_id = prod.id) + JOIN product_product_manuf_for_partner_rel rel + ON (rel.product_id = prod.id) + WHERE sol.display_type IS NULL + AND sol.order_id = %s + GROUP BY rel.product_id + """, + (self.id,), + ), + ) + for _, allowed_partner_ids in self.env.cr.fetchall(): + # The product has limitations but the partner doesn't have + # a commercial entity, thus the condition is not fulfilled. + if not commercial_entity and allowed_partner_ids: + return False + + # The product has limitations and the commercial entity of + # the partner partner is not listed as allowed. + elif commercial_entity.id not in allowed_partner_ids: + return False + + return True diff --git a/sale_exception_product_sale_manufactured_for/pyproject.toml b/sale_exception_product_sale_manufactured_for/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_exception_product_sale_manufactured_for/readme/CONTRIBUTORS.md b/sale_exception_product_sale_manufactured_for/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..bc7703fe964 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/readme/CONTRIBUTORS.md @@ -0,0 +1,8 @@ +- [Camptocamp](https://www.camptocamp.com): + - Carlos Serra-Toro \<\> + - Simone Orsi \<\> + - Thierry Ducrest \<\> + +- [Trobz](https://trobz.com): + - Son Ho \<\> + - Nhan Tran \<\> diff --git a/sale_exception_product_sale_manufactured_for/readme/CREDITS.md b/sale_exception_product_sale_manufactured_for/readme/CREDITS.md new file mode 100644 index 00000000000..e34bfbc4bc2 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/readme/CREDITS.md @@ -0,0 +1 @@ +**Financial support** \* Cosanum \* Camptocamp R&D diff --git a/sale_exception_product_sale_manufactured_for/readme/DESCRIPTION.md b/sale_exception_product_sale_manufactured_for/readme/DESCRIPTION.md new file mode 100644 index 00000000000..1e568217a6e --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +The partner set in the sales order can order only if he/she has a +commercial entity that is listed as one of the partners for which the +products can be manufactured for. diff --git a/sale_exception_product_sale_manufactured_for/static/description/icon.png b/sale_exception_product_sale_manufactured_for/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_exception_product_sale_manufactured_for/static/description/icon.png differ diff --git a/sale_exception_product_sale_manufactured_for/static/description/index.html b/sale_exception_product_sale_manufactured_for/static/description/index.html new file mode 100644 index 00000000000..e048076e851 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Sale Exception Product Manufactured for Customer + + + +
+

Sale Exception Product Manufactured for Customer

+ + +

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

+

The partner set in the sales order can order only if he/she has a +commercial entity that is listed as one of the partners for which the +products can be manufactured for.

+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

Financial support * Cosanum * Camptocamp R&D

+
+
+

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_exception_product_sale_manufactured_for/tests/__init__.py b/sale_exception_product_sale_manufactured_for/tests/__init__.py new file mode 100644 index 00000000000..be08878af88 --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) +from . import test_sale_exception diff --git a/sale_exception_product_sale_manufactured_for/tests/test_sale_exception.py b/sale_exception_product_sale_manufactured_for/tests/test_sale_exception.py new file mode 100644 index 00000000000..6efc9a0d1bf --- /dev/null +++ b/sale_exception_product_sale_manufactured_for/tests/test_sale_exception.py @@ -0,0 +1,77 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo.addons.base.tests.common import BaseCommon + + +class TestSaleException(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.exception = cls.env.ref( + "sale_exception_product_sale_manufactured_for.exception_partner_can_order" + ) + cls.exception.active = True + + partner_order = cls.env.ref("base.res_partner_1") + cls.partner_manufactured_for = cls.env.ref("base.res_partner_3") + cls.product = cls.env.ref("product.product_product_6") + cls.product.manufactured_for_partner_ids |= cls.partner_manufactured_for + + cls.sale = cls.env["sale.order"].create( + { + "partner_id": partner_order.id, + "partner_invoice_id": partner_order.id, + "partner_shipping_id": partner_order.id, + "order_line": [ + ( + 0, + 0, + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 1, + "product_uom": cls.product.uom_id.id, + "price_unit": 1, + }, + ) + ], + } + ) + + def test_commercial_partner_not_valid(self): + self.sale.partner_id.commercial_partner_id = self.env.ref("base.res_partner_2") + self.sale.action_confirm() + self.assertEqual(self.sale.state, "draft") + self.assertEqual(len(self.sale.exception_ids), 1) + self.assertEqual(self.sale.exception_ids[0], self.exception) + + def test_commercial_partner_is_valid(self): + self.sale.partner_id.commercial_partner_id = self.sale.order_line[ + 0 + ].product_id.manufactured_for_partner_ids[0] + self.sale.action_confirm() + self.assertEqual(self.sale.state, "sale") + self.assertFalse(self.sale.exception_ids) + + def test_commercial_partner_empty(self): + self.sale.partner_id.commercial_partner_id = False + self.sale.action_confirm() + self.assertEqual(self.sale.state, "draft") + self.assertEqual(len(self.sale.exception_ids), 1) + self.assertEqual(self.sale.exception_ids[0], self.exception) + + def test_product_without_limits_partner_with_commercial_entity(self): + self.product.manufactured_for_partner_ids = False + self.sale.partner_id.commercial_partner_id = self.partner_manufactured_for + self.sale.action_confirm() + self.assertEqual(self.sale.state, "sale") + self.assertFalse(self.sale.exception_ids) + + def test_product_without_limits_partner_without_commercial_entity(self): + self.product.manufactured_for_partner_ids = False + self.sale.partner_id.commercial_partner_id = False + self.sale.action_confirm() + self.assertEqual(self.sale.state, "sale") + self.assertFalse(self.sale.exception_ids) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..58347d94b7d --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-product_sale_manufactured_for @ git+https://github.com/OCA/product-attribute.git@refs/pull/1801/head#subdirectory=product_sale_manufactured_for +odoo-addon-sale_exception @ git+https://github.com/OCA/sale-workflow.git@refs/pull/3359/head#subdirectory=sale_exception