Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions multi_pms_properties/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``::

<field name="pms_property_ids" groups="pms.group_pms_user" />
<field name="pms_property_ids" groups="!pms.group_pms_user" invisible="1" />

Bug Tracker
===========

Expand Down
9 changes: 9 additions & 0 deletions multi_pms_properties/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``::

<field name="pms_property_ids" groups="pms.group_pms_user" />
<field name="pms_property_ids" groups="!pms.group_pms_user" invisible="1" />
10 changes: 10 additions & 0 deletions multi_pms_properties/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<tt class="docutils literal">check_pms_properties like field attribute to check relational record properties consistence</tt>
<tt class="docutils literal">This module not implement propety dependent fields</tt></p>
</li>
<li><p class="first"><tt class="docutils literal">check_pms_properties</tt> injects a domain referring to the property field of the
model, so any view showing such a field must keep <tt class="docutils literal">pms_property_id(s)</tt>
available for every group combination. Restricting it with <tt class="docutils literal">groups</tt> makes Odoo
refuse to validate the view. To hide it from some users, add a companion node
instead, the same way core does with <tt class="docutils literal">company_id</tt> and <tt class="docutils literal">check_company</tt>:</p>
<pre class="literal-block">
&lt;field name=&quot;pms_property_ids&quot; groups=&quot;pms.group_pms_user&quot; /&gt;
&lt;field name=&quot;pms_property_ids&quot; groups=&quot;!pms.group_pms_user&quot; invisible=&quot;1&quot; /&gt;
</pre>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
Expand Down
1 change: 1 addition & 0 deletions pms/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 43 additions & 0 deletions pms/tests/test_view_check_pms_properties.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions pms/views/product_pricelist_item_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
widget="many2many_tags"
options="{'no_create': True,'no_open': True}"
/>
<!-- Kept available (hidden) for non PMS users: the domain
injected by multi_pms_properties into product_tmpl_id and
pricelist_id refers to pms_property_ids. -->
<field
name="pms_property_ids"
groups="!pms.group_pms_user"
invisible="1"
/>
</xpath>
<xpath expr="//field[@name='min_quantity']" position="after">
<label for="date_start_consumption" string="Consumption" />
Expand Down
11 changes: 11 additions & 0 deletions pms/views/product_pricelist_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
options="{'no_create': True,'no_open': True}"
attrs="{'invisible': [('is_pms_available', '=', False)]}"
/>
<!-- multi_pms_properties injects a domain referring to
pms_property_ids into every relational field of this model
declared with check_pms_properties=True, item_ids among them.
A view cannot use a field restricted to a narrower group, so
the field must stay available (hidden) for the other users.
Same pattern as company_id/check_company in core views. -->
<field
name="pms_property_ids"
groups="!pms.group_pms_user"
invisible="1"
/>
</xpath>
<xpath expr="//field[@name='country_group_ids']" position="before">
<field
Expand Down
Loading