diff --git a/multi_pms_properties/README.rst b/multi_pms_properties/README.rst index 3435c0c5f5..979da5b158 100644 --- a/multi_pms_properties/README.rst +++ b/multi_pms_properties/README.rst @@ -59,6 +59,15 @@ Usage ``check_pms_properties like field attribute to check relational record properties consistence`` ``This module not implement propety dependent fields`` +* ``check_pms_properties`` injects a domain referring to the property field of the + model, so any view showing such a field must keep ``pms_property_id(s)`` + available for every group combination. Restricting it with ``groups`` makes Odoo + refuse to validate the view. To hide it from some users, add a companion node + instead, the same way core does with ``company_id`` and ``check_company``:: + + + + Bug Tracker =========== diff --git a/multi_pms_properties/readme/USAGE.rst b/multi_pms_properties/readme/USAGE.rst index daa058b5f3..df817d6869 100644 --- a/multi_pms_properties/readme/USAGE.rst +++ b/multi_pms_properties/readme/USAGE.rst @@ -3,3 +3,12 @@ ``_check_pms_properties_auto like model attribute to autocheck on create/write`` ``check_pms_properties like field attribute to check relational record properties consistence`` ``This module not implement propety dependent fields`` + +* ``check_pms_properties`` injects a domain referring to the property field of the + model, so any view showing such a field must keep ``pms_property_id(s)`` + available for every group combination. Restricting it with ``groups`` makes Odoo + refuse to validate the view. To hide it from some users, add a companion node + instead, the same way core does with ``company_id`` and ``check_company``:: + + + diff --git a/multi_pms_properties/static/description/index.html b/multi_pms_properties/static/description/index.html index 01037cc4fa..e843ab757d 100644 --- a/multi_pms_properties/static/description/index.html +++ b/multi_pms_properties/static/description/index.html @@ -406,6 +406,16 @@

Usage

check_pms_properties like field attribute to check relational record properties consistence This module not implement propety dependent fields

+
  • check_pms_properties injects a domain referring to the property field of the +model, so any view showing such a field must keep pms_property_id(s) +available for every group combination. Restricting it with groups makes Odoo +refuse to validate the view. To hide it from some users, add a companion node +instead, the same way core does with company_id and check_company:

    +
    +<field name="pms_property_ids" groups="pms.group_pms_user" />
    +<field name="pms_property_ids" groups="!pms.group_pms_user" invisible="1" />
    +
    +
  • diff --git a/pms/tests/__init__.py b/pms/tests/__init__.py index 910f749b93..e12f0127e7 100644 --- a/pms/tests/__init__.py +++ b/pms/tests/__init__.py @@ -46,3 +46,4 @@ from . import test_pms_payment from . import test_res_partner from . import test_pms_property +from . import test_view_check_pms_properties diff --git a/pms/tests/test_view_check_pms_properties.py b/pms/tests/test_view_check_pms_properties.py new file mode 100644 index 0000000000..dea884522a --- /dev/null +++ b/pms/tests/test_view_check_pms_properties.py @@ -0,0 +1,43 @@ +# Copyright 2026 Commit [Sun] +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from unittest.mock import patch + +from odoo import fields +from odoo.tests import common + +from odoo.addons.multi_pms_properties import _description_domain + + +class TestViewCheckPmsProperties(common.TransactionCase): + """Views must keep the property field available for every group combination. + + ``multi_pms_properties`` injects a domain into every relational field declared + with ``check_pms_properties=True``, and that domain refers to the property + field of the model (``pms_property_ids`` or ``pms_property_id``). Odoo refuses + to validate a view where a field used in the domain of another field is + restricted to a narrower group, so restricting the property field with + ``groups`` breaks the whole view, and with it the module load. + + The injection only happens when ``multi_pms_properties`` is loaded through + ``server_wide_modules``, which is not the case while running tests. The patch + is therefore applied explicitly here, so the check reproduces a real + deployment instead of silently passing. + """ + + # Views showing fields whose injected domain refers to the property field + VIEWS = [ + "pms.product_pricelist_view_form", + "pms.product_pricelist_item_view_form", + "pms.product_template_view_form", + "pms.res_partner_view_form", + ] + + def test_views_validate_with_injected_property_domain(self): + with patch.object( + fields._Relational, "check_pms_properties", False, create=True + ), patch.object( + fields._Relational, "_description_domain", _description_domain, create=True + ): + for xml_id in self.VIEWS: + with self.subTest(view=xml_id): + self.env.ref(xml_id)._check_xml() diff --git a/pms/views/product_pricelist_item_views.xml b/pms/views/product_pricelist_item_views.xml index 279f0629c3..e8498c9322 100644 --- a/pms/views/product_pricelist_item_views.xml +++ b/pms/views/product_pricelist_item_views.xml @@ -27,6 +27,14 @@ widget="many2many_tags" options="{'no_create': True,'no_open': True}" /> + +