diff --git a/sale_partner_address_restrict/README.rst b/sale_partner_address_restrict/README.rst index 113233026a0d..cb1dbd6c4983 100644 --- a/sale_partner_address_restrict/README.rst +++ b/sale_partner_address_restrict/README.rst @@ -7,7 +7,7 @@ Sale Partner Address Restrict !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:026c9b3f140a8467f57aa94ea7d898de824516f18656d2d7e750a60246399e3b + !! source digest: sha256:8861897ace83b8b0b2d9fea26ce71f146cc21b0b46a00ea4fb331af9a2dcf963 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -36,6 +36,15 @@ to only addresses of the selected customer. .. contents:: :local: +Configuration +============= + +- Go to Sales > Configuration > Settings > Quotation & Orders > Sale + Partner Address Restriction +- Check the box if you want to restrict available partners for Delivery + and Invoicing addresses to partners that belong to the selected + Customer. + Bug Tracker =========== diff --git a/sale_partner_address_restrict/__manifest__.py b/sale_partner_address_restrict/__manifest__.py index 11cff40f3269..8bfc4d4c76b2 100644 --- a/sale_partner_address_restrict/__manifest__.py +++ b/sale_partner_address_restrict/__manifest__.py @@ -14,5 +14,5 @@ "depends": [ "sale", ], - "data": ["views/sale_order_view.xml"], + "data": ["views/sale_order_view.xml", "views/res_config_settings.xml"], } diff --git a/sale_partner_address_restrict/models/__init__.py b/sale_partner_address_restrict/models/__init__.py index 6aacb753131f..20972a4c7d29 100644 --- a/sale_partner_address_restrict/models/__init__.py +++ b/sale_partner_address_restrict/models/__init__.py @@ -1 +1,3 @@ from . import sale_order +from . import res_company +from . import res_config_settings diff --git a/sale_partner_address_restrict/models/res_company.py b/sale_partner_address_restrict/models/res_company.py new file mode 100644 index 000000000000..ac0b000eb3da --- /dev/null +++ b/sale_partner_address_restrict/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + sale_partner_address_restriction = fields.Boolean( + help="Check this box if you want to restrict partner addresses selection " + "in sale orders. They should depends on the Customer filled in." + ) diff --git a/sale_partner_address_restrict/models/res_config_settings.py b/sale_partner_address_restrict/models/res_config_settings.py new file mode 100644 index 000000000000..d354e3aaa456 --- /dev/null +++ b/sale_partner_address_restrict/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + sale_partner_address_restriction = fields.Boolean( + related="company_id.sale_partner_address_restriction", + readonly=False, + ) diff --git a/sale_partner_address_restrict/models/sale_order.py b/sale_partner_address_restrict/models/sale_order.py index 1e77c7de028f..29a65077dcd0 100644 --- a/sale_partner_address_restrict/models/sale_order.py +++ b/sale_partner_address_restrict/models/sale_order.py @@ -8,9 +8,16 @@ class SaleOrder(models.Model): @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) + if ( + order.company_id.sale_partner_address_restriction + and 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( _( diff --git a/sale_partner_address_restrict/readme/CONFIGURE.md b/sale_partner_address_restrict/readme/CONFIGURE.md new file mode 100644 index 000000000000..3cc2274d7515 --- /dev/null +++ b/sale_partner_address_restrict/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +- Go to Sales \> Configuration \> Settings \> Quotation & Orders \> Sale Partner Address Restriction +- Check the box if you want to restrict available partners for Delivery and Invoicing addresses to + partners that belong to the selected Customer. diff --git a/sale_partner_address_restrict/static/description/index.html b/sale_partner_address_restrict/static/description/index.html index f3ef289a5655..05dc65bde274 100644 --- a/sale_partner_address_restrict/static/description/index.html +++ b/sale_partner_address_restrict/static/description/index.html @@ -367,7 +367,7 @@

Sale Partner Address Restrict

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:026c9b3f140a8467f57aa94ea7d898de824516f18656d2d7e750a60246399e3b +!! source digest: sha256:8861897ace83b8b0b2d9fea26ce71f146cc21b0b46a00ea4fb331af9a2dcf963 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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 @@ -375,17 +375,28 @@

Sale Partner Address Restrict

Table of contents

+
+

Configuration

+ +
-

Bug Tracker

+

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 @@ -393,21 +404,21 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association diff --git a/sale_partner_address_restrict/tests/test_sale_order.py b/sale_partner_address_restrict/tests/test_sale_order.py index 7dff1e31cf69..6c0cc51b24c9 100644 --- a/sale_partner_address_restrict/tests/test_sale_order.py +++ b/sale_partner_address_restrict/tests/test_sale_order.py @@ -1,9 +1,10 @@ from odoo.exceptions import ValidationError from odoo.tests import Form -from odoo.tests.common import TransactionCase +from odoo.addons.base.tests.common import BaseCommon -class TestSaleOrder(TransactionCase): + +class TestSaleOrder(BaseCommon): @classmethod def setUpClass(cls): super().setUpClass() @@ -17,6 +18,7 @@ def setUpClass(cls): cls.partner2 = cls.env["res.partner"].create({"name": "Test Partner 2"}) cls.partner3 = cls.env["res.partner"].create({"name": "Test Partner 3"}) + cls.env.company.sale_partner_address_restriction = True def test_sale_order_address_domain(self): order_form = Form(self.env["sale.order"]) @@ -53,3 +55,13 @@ def test_sale_order_address_constraint(self): "partner_shipping_id": self.child_2.id, } ) + + def test_sale_order_address_no_constraint(self): + self.env.company.sale_partner_address_restriction = False + 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/res_config_settings.xml b/sale_partner_address_restrict/views/res_config_settings.xml new file mode 100644 index 000000000000..f1bc55b37a8e --- /dev/null +++ b/sale_partner_address_restrict/views/res_config_settings.xml @@ -0,0 +1,22 @@ + + + + + res.config.settings.view.form.inherit.sale + res.config.settings + + + + + + + + + + +