diff --git a/sale_partner_address_restrict/README.rst b/sale_partner_address_restrict/README.rst new file mode 100644 index 00000000000..b3f461496e5 --- /dev/null +++ b/sale_partner_address_restrict/README.rst @@ -0,0 +1,77 @@ +============================= +Sale Partner Address Restrict +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:026c9b3f140a8467f57aa94ea7d898de824516f18656d2d7e750a60246399e3b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/17.0/sale_partner_address_restrict + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-sale_partner_address_restrict + :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/partner-contact&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module restricts the addresses to be used in the sales order form +to only addresses of the selected customer. + +**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 +------- + +* ForgeFlow + +Contributors +------------ + +- Marina Alapont + +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/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_partner_address_restrict/__init__.py b/sale_partner_address_restrict/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_partner_address_restrict/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_partner_address_restrict/__manifest__.py b/sale_partner_address_restrict/__manifest__.py new file mode 100644 index 00000000000..9250fa2843d --- /dev/null +++ b/sale_partner_address_restrict/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Sale Partner Address Restrict", + "summary": "Restrict addresses domain in the sales order form" + " taking into account the partner selected", + "version": "17.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/partner-contact", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": [ + "sale", + ], + "data": ["views/sale_order_view.xml"], +} diff --git a/sale_partner_address_restrict/i18n/it.po b/sale_partner_address_restrict/i18n/it.po new file mode 100644 index 00000000000..86a557f5437 --- /dev/null +++ b/sale_partner_address_restrict/i18n/it.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_address_restrict +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-26 12: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_partner_address_restrict +#. odoo-python +#: code:addons/sale_partner_address_restrict/models/sale_order.py:0 +#, python-format +msgid "" +"Invoice and shipping addresses must be child addresses of the selected " +"partner or the selected partner itself." +msgstr "" +"Gli indirizzi di fatturazione e di spedizione devono essere indirizzi figli " +"del partner selezionato o del partner selezionato stesso." + +#. module: sale_partner_address_restrict +#: model:ir.model,name:sale_partner_address_restrict.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" diff --git a/sale_partner_address_restrict/i18n/sale_partner_address_restrict.pot b/sale_partner_address_restrict/i18n/sale_partner_address_restrict.pot new file mode 100644 index 00000000000..d0d504491c4 --- /dev/null +++ b/sale_partner_address_restrict/i18n/sale_partner_address_restrict.pot @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_partner_address_restrict +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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_partner_address_restrict +#. odoo-python +#: code:addons/sale_partner_address_restrict/models/sale_order.py:0 +#, python-format +msgid "" +"Invoice and shipping addresses must be child addresses of the selected " +"partner or the selected partner itself." +msgstr "" + +#. module: sale_partner_address_restrict +#: model:ir.model,name:sale_partner_address_restrict.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/sale_partner_address_restrict/models/__init__.py b/sale_partner_address_restrict/models/__init__.py new file mode 100644 index 00000000000..6aacb753131 --- /dev/null +++ b/sale_partner_address_restrict/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/sale_partner_address_restrict/models/sale_order.py b/sale_partner_address_restrict/models/sale_order.py new file mode 100644 index 00000000000..1e77c7de028 --- /dev/null +++ b/sale_partner_address_restrict/models/sale_order.py @@ -0,0 +1,20 @@ +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.constrains("partner_id", "partner_invoice_id", "partner_shipping_id") + def _check_partner_addresses(self): + for order in self: + if order.partner_id and ( + (order.partner_invoice_id.commercial_partner_id != order.partner_id) + or (order.partner_shipping_id.commercial_partner_id != order.partner_id) + ): + raise ValidationError( + _( + "Invoice and shipping addresses must be child addresses" + " of the selected partner or the selected partner itself." + ) + ) diff --git a/sale_partner_address_restrict/pyproject.toml b/sale_partner_address_restrict/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_partner_address_restrict/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_partner_address_restrict/readme/CONTRIBUTORS.md b/sale_partner_address_restrict/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..25a2caefd61 --- /dev/null +++ b/sale_partner_address_restrict/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Marina Alapont \<\> diff --git a/sale_partner_address_restrict/readme/DESCRIPTION.md b/sale_partner_address_restrict/readme/DESCRIPTION.md new file mode 100644 index 00000000000..9b39e317378 --- /dev/null +++ b/sale_partner_address_restrict/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module restricts the addresses to be used in the sales order form to only +addresses of the selected customer. diff --git a/sale_partner_address_restrict/static/description/icon.png b/sale_partner_address_restrict/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_partner_address_restrict/static/description/icon.png differ diff --git a/sale_partner_address_restrict/static/description/index.html b/sale_partner_address_restrict/static/description/index.html new file mode 100644 index 00000000000..277a93a6b7a --- /dev/null +++ b/sale_partner_address_restrict/static/description/index.html @@ -0,0 +1,421 @@ + + + + + +Sale Partner Address Restrict + + + +
+

Sale Partner Address Restrict

+ + +

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

+

This module restricts the addresses to be used in the sales order form +to only addresses of the selected customer.

+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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/partner-contact project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_partner_address_restrict/tests/__init__.py b/sale_partner_address_restrict/tests/__init__.py new file mode 100644 index 00000000000..6f699d0d8ba --- /dev/null +++ b/sale_partner_address_restrict/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order diff --git a/sale_partner_address_restrict/tests/test_sale_order.py b/sale_partner_address_restrict/tests/test_sale_order.py new file mode 100644 index 00000000000..7dff1e31cf6 --- /dev/null +++ b/sale_partner_address_restrict/tests/test_sale_order.py @@ -0,0 +1,55 @@ +from odoo.exceptions import ValidationError +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestSaleOrder(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner1 = cls.env["res.partner"].create({"name": "Test Partner 1"}) + cls.child_1 = cls.env["res.partner"].create( + {"name": "Child 1", "parent_id": cls.partner1.id} + ) + cls.child_2 = cls.env["res.partner"].create( + {"name": "Child 2", "parent_id": cls.partner1.id} + ) + + cls.partner2 = cls.env["res.partner"].create({"name": "Test Partner 2"}) + cls.partner3 = cls.env["res.partner"].create({"name": "Test Partner 3"}) + + def test_sale_order_address_domain(self): + order_form = Form(self.env["sale.order"]) + order_form.partner_id = self.partner1 + sale_order = order_form.save() + + expected_domain = [ + ("commercial_partner_id", "=", sale_order.partner_id.id), + "|", + ("company_id", "=", False), + ("company_id", "=", sale_order.company_id.id), + ] + + partners = self.env["res.partner"].search(expected_domain) + self.assertEqual(len(partners), 3) + + with Form(sale_order) as sale_order: + sale_order.partner_id = self.partner2 + expected_domain = [ + ("commercial_partner_id", "=", sale_order.partner_id.id), + "|", + ("company_id", "=", False), + ("company_id", "=", sale_order.company_id.id), + ] + partners = self.env["res.partner"].search(expected_domain) + self.assertEqual(len(partners), 1) + + def test_sale_order_address_constraint(self): + with self.assertRaises(ValidationError): + self.env["sale.order"].create( + { + "partner_id": self.partner1.id, + "partner_invoice_id": self.partner2.id, + "partner_shipping_id": self.child_2.id, + } + ) diff --git a/sale_partner_address_restrict/views/sale_order_view.xml b/sale_partner_address_restrict/views/sale_order_view.xml new file mode 100644 index 00000000000..999b769db6b --- /dev/null +++ b/sale_partner_address_restrict/views/sale_order_view.xml @@ -0,0 +1,29 @@ + + + + + + sale.order.form (in partner_invoicing_mode) + sale.order + + + + [ + ('commercial_partner_id', '=', partner_id), + '|', + ('company_id', '=', False), + ('company_id', '=', company_id), + ] + + + [ + ('commercial_partner_id', '=', partner_id), + '|', + ('company_id', '=', False), + ('company_id', '=', company_id), + ] + + + +