Skip to content

Commit accee6f

Browse files
committed
[19.0][MIG] product_multi_company: fix access rights error
1 parent 6197222 commit accee6f

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

product_multi_company/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"version": "19.0.1.0.0",
1111
"license": "AGPL-3",
1212
"depends": ["base_multi_company", "product"],
13-
"data": ["views/product_template_view.xml"],
13+
"data": [
14+
"views/product_template_view.xml",
15+
"views/product_product_view.xml",
16+
],
1417
"post_init_hook": "post_init_hook",
1518
}

product_multi_company/tests/test_product_multi_company.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
33
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
44

5+
from lxml import etree
6+
57
from odoo.exceptions import AccessError
68
from odoo.tests import Form, common
79

@@ -136,3 +138,61 @@ def test_search_product(self):
136138
]
137139
)
138140
self.assertEqual(searched_products, expected_products)
141+
142+
def test_product_variant_tree_view_patched(self):
143+
"""
144+
Ensures that the standalone product.product list view is properly patched
145+
to prevent AccessErrors for restricted users.
146+
"""
147+
tree_view = self.env.ref("product.product_product_tree_view")
148+
tree_arch = etree.fromstring(tree_view.get_combined_arch())
149+
150+
company_id_nodes = tree_arch.xpath("//field[@name='company_id']")
151+
self.assertTrue(
152+
company_id_nodes,
153+
"TEST FAILURE: company_id field is completely missing from the base tree view.",
154+
)
155+
156+
column_invisible = company_id_nodes[0].get("column_invisible")
157+
self.assertIsNotNone(
158+
column_invisible,
159+
"TEST FAILURE: The XML fix is NOT applied! 'company_id' is visible in the list view.",
160+
)
161+
self.assertIn(
162+
str(column_invisible),
163+
["True", "1", "true"],
164+
f"TEST FAILURE: company_id has column_invisible='{column_invisible}'. Expected 'True'.",
165+
)
166+
167+
company_ids_nodes = tree_arch.xpath("//field[@name='company_ids']")
168+
self.assertTrue(
169+
company_ids_nodes,
170+
"TEST FAILURE: The XML fix is NOT applied! 'company_ids' is missing from the list view.",
171+
)
172+
173+
groups = company_ids_nodes[0].get("groups")
174+
self.assertEqual(
175+
str(groups),
176+
"base.group_multi_company",
177+
f"TEST FAILURE: company_ids groups attribute is '{groups}', expected 'base.group_multi_company'.",
178+
)
179+
180+
def test_product_variant_payload_simulation(self):
181+
"""
182+
Simulates the web client payload generation to ensure restricted
183+
fields are properly hidden and not requested by the frontend.
184+
"""
185+
tree_view = self.env.ref("product.product_product_tree_view")
186+
tree_arch = etree.fromstring(tree_view.sudo().get_combined_arch())
187+
188+
specification = {"name": {}}
189+
for node in tree_arch.xpath("//field[@name='company_id']"):
190+
invisible = node.get("column_invisible") in ["True", "1", "true"]
191+
if not invisible:
192+
specification["company_id"] = {"fields": {"display_name": {}}}
193+
194+
self.assertNotIn(
195+
"company_id",
196+
specification,
197+
"TEST FAILURE: company_id is exposed in the view arch and would be requested by the web client.",
198+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="product_product_tree_view" model="ir.ui.view">
4+
<field name="model">product.product</field>
5+
<field name="inherit_id" ref="product.product_product_tree_view" />
6+
<field name="arch" type="xml">
7+
<xpath expr="//field[@name='company_id']" position="attributes">
8+
<attribute name="column_invisible">True</attribute>
9+
</xpath>
10+
11+
<xpath expr="//field[@name='company_id']" position="after">
12+
<field
13+
name="company_ids"
14+
widget="many2many_tags"
15+
groups="base.group_multi_company"
16+
optional="hide"
17+
/>
18+
</xpath>
19+
</field>
20+
</record>
21+
</odoo>

0 commit comments

Comments
 (0)