From e0c53c6d7aeb96d6ec2bba6f94d3734a9a1e3f92 Mon Sep 17 00:00:00 2001 From: GuillemCForgeFlow Date: Fri, 2 Jun 2023 17:35:54 +0200 Subject: [PATCH 1/3] [ADD]multicompany_property_account_payment_term_restriction Glue module between multicompany_property_account and account_payment_term_restriction modules (sale and purchase extensions) --- .../README.rst | 46 ++++++++++++++++++ .../__init__.py | 1 + .../__manifest__.py | 19 ++++++++ .../models/__init__.py | 1 + .../models/partner.py | 24 ++++++++++ .../tests/__init__.py | 1 + ...operty_account_payment_term_restriction.py | 9 ++++ .../views/partner_views.xml | 47 +++++++++++++++++++ 8 files changed, 148 insertions(+) create mode 100644 multicompany_property_account_payment_term_restriction/README.rst create mode 100644 multicompany_property_account_payment_term_restriction/__init__.py create mode 100644 multicompany_property_account_payment_term_restriction/__manifest__.py create mode 100644 multicompany_property_account_payment_term_restriction/models/__init__.py create mode 100644 multicompany_property_account_payment_term_restriction/models/partner.py create mode 100644 multicompany_property_account_payment_term_restriction/tests/__init__.py create mode 100644 multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py create mode 100644 multicompany_property_account_payment_term_restriction/views/partner_views.xml diff --git a/multicompany_property_account_payment_term_restriction/README.rst b/multicompany_property_account_payment_term_restriction/README.rst new file mode 100644 index 00000000..f5ef19cc --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/README.rst @@ -0,0 +1,46 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png + :target: https://www.gnu.org/licenses/lgpl + :alt: License: LGPL-3 + +====================================================== +Multicompany Property Account Payment Term Restriction +====================================================== + +This module is part of a set of modules that allow to set property fields on +a given model for multiple companies simultaneously. Specifically this module: + +* Restricts setting Payment Terms on Partners based on the settings. If a Payment Term is only applicable on Sales documents, trying to set this Payment Term as the Vendor Payment Term on a partner, will trigger a Validation Error. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/133/11.0 + + +Credits +======= + +Contributors +------------ + +* Guillem Casassas + +Do not contact contributors directly about support or help with technical issues. + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/multicompany_property_account_payment_term_restriction/__init__.py b/multicompany_property_account_payment_term_restriction/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/multicompany_property_account_payment_term_restriction/__manifest__.py b/multicompany_property_account_payment_term_restriction/__manifest__.py new file mode 100644 index 00000000..b436e3ef --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). +{ + "name": "Multi Company Account Payment Term Restriction", + "version": "13.0.1.0.0", + "summary": "Payment Term Multi-Company Restrictions", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/ForgeFlow/multicompany-fixes", + "license": "LGPL-3", + "depends": [ + "multicompany_property_account", + "account_payment_term_restriction_sale", + "account_payment_term_restriction_purchase", + ], + "data": ["views/partner_views.xml"], + "installable": True, + "application": False, + "auto_install": True, +} diff --git a/multicompany_property_account_payment_term_restriction/models/__init__.py b/multicompany_property_account_payment_term_restriction/models/__init__.py new file mode 100644 index 00000000..4da81fa3 --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/models/__init__.py @@ -0,0 +1 @@ +from . import partner diff --git a/multicompany_property_account_payment_term_restriction/models/partner.py b/multicompany_property_account_payment_term_restriction/models/partner.py new file mode 100644 index 00000000..55cb2775 --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/models/partner.py @@ -0,0 +1,24 @@ +from odoo import api, models + + +class PartnerProperty(models.TransientModel): + _inherit = "res.partner.property" + + @api.model + def _get_payment_term_fields_applicable_on_mapping(self): + apt_model = self.env["account.payment.term"] + return { + "property_payment_term_id": apt_model.get_sale_applicable_on(), + "property_supplier_payment_term_id": apt_model.get_purchase_applicable_on(), + } + + def set_property(self, obj, fieldname, value, properties): + if self.env.context.get("skip_payment_term_restriction", False): + return super().set_property(obj, fieldname, value, properties) + pt_fields_dict = self._get_payment_term_fields_applicable_on_mapping() + if fieldname in pt_fields_dict.keys(): + payment_term = self.env["account.payment.term"].browse(value) + applicable_on = pt_fields_dict.get(fieldname) + if payment_term.exists(): + payment_term.check_not_applicable(applicable_on, record=obj) + super().set_property(obj, fieldname, value, properties) diff --git a/multicompany_property_account_payment_term_restriction/tests/__init__.py b/multicompany_property_account_payment_term_restriction/tests/__init__.py new file mode 100644 index 00000000..538a2234 --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/tests/__init__.py @@ -0,0 +1 @@ +from . import test_multicompany_property_account_payment_term_restriction diff --git a/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py b/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py new file mode 100644 index 00000000..55e9a0e7 --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py @@ -0,0 +1,9 @@ +# Copyright 2023 ForgeFlow, S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo.addons.multicompany_property_account.tests import test_multicompany + + +class TestMulticompanyProperty(test_multicompany.TestMulticompanyProperty): + def test_partner(self): + super().test_partner() diff --git a/multicompany_property_account_payment_term_restriction/views/partner_views.xml b/multicompany_property_account_payment_term_restriction/views/partner_views.xml new file mode 100644 index 00000000..6f3d7f98 --- /dev/null +++ b/multicompany_property_account_payment_term_restriction/views/partner_views.xml @@ -0,0 +1,47 @@ + + + + res.partner.property.tree - multicompany_property_account_payment_term_restriction + res.partner.property + + + + [('applicable_on', 'in', ['sale', 'all'])] + + + [('applicable_on', 'in', ['purchase', 'all'])] + + + + + res.partner.property.form - multicompany_property_account_payment_term_restriction + res.partner.property + + + + [('applicable_on', 'in', ['sale', 'all'])] + + + [('applicable_on', 'in', ['purchase', 'all'])] + + + + From 20235b7e9745d0ad8489f5455a8f8bc9278cae3f Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Thu, 22 Jun 2023 14:31:09 +0530 Subject: [PATCH 2/3] [IMP] multicompany_property_account_payment_term_restriction: black, isort, prettier --- .../multicompany_property_account_payment_term_restriction | 1 + .../setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/multicompany_property_account_payment_term_restriction/odoo/addons/multicompany_property_account_payment_term_restriction create mode 100644 setup/multicompany_property_account_payment_term_restriction/setup.py diff --git a/setup/multicompany_property_account_payment_term_restriction/odoo/addons/multicompany_property_account_payment_term_restriction b/setup/multicompany_property_account_payment_term_restriction/odoo/addons/multicompany_property_account_payment_term_restriction new file mode 120000 index 00000000..105c7222 --- /dev/null +++ b/setup/multicompany_property_account_payment_term_restriction/odoo/addons/multicompany_property_account_payment_term_restriction @@ -0,0 +1 @@ +../../../../multicompany_property_account_payment_term_restriction \ No newline at end of file diff --git a/setup/multicompany_property_account_payment_term_restriction/setup.py b/setup/multicompany_property_account_payment_term_restriction/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/multicompany_property_account_payment_term_restriction/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 5654d9b8fd8af02eac5075cabec54e95b0f9e3ed Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Thu, 22 Jun 2023 16:37:13 +0530 Subject: [PATCH 3/3] [MIG] multicompany_property_account_payment_term_restriction: Migration to 15.0 --- .../__manifest__.py | 2 +- ...st_multicompany_property_account_payment_term_restriction.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/multicompany_property_account_payment_term_restriction/__manifest__.py b/multicompany_property_account_payment_term_restriction/__manifest__.py index b436e3ef..9652a5ea 100644 --- a/multicompany_property_account_payment_term_restriction/__manifest__.py +++ b/multicompany_property_account_payment_term_restriction/__manifest__.py @@ -2,7 +2,7 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). { "name": "Multi Company Account Payment Term Restriction", - "version": "13.0.1.0.0", + "version": "15.0.1.0.0", "summary": "Payment Term Multi-Company Restrictions", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/ForgeFlow/multicompany-fixes", diff --git a/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py b/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py index 55e9a0e7..91b8aa6c 100644 --- a/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py +++ b/multicompany_property_account_payment_term_restriction/tests/test_multicompany_property_account_payment_term_restriction.py @@ -6,4 +6,4 @@ class TestMulticompanyProperty(test_multicompany.TestMulticompanyProperty): def test_partner(self): - super().test_partner() + return super().test_partner()