From 51e12ca394eb3b329bb70d531e99d203b715344d Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 30 Nov 2022 11:03:52 +0000 Subject: [PATCH] [FIX] base: continue stack post-processing after adding ` ``` The view post-processing adds a temporary ` ``` This is to make an `AND` connection with the two groups: the user is required to have both groups in order to see the field. Currently, there is no way to make that `AND` combination on the same node. The below: ```xml ``` would be an `OR` connection, not an `AND.` Hence this temporary added ` --- odoo/addons/base/models/ir_ui_view.py | 4 ++-- odoo/addons/base/tests/test_views.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index f3fd90e8738..08faf0ce17e 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -1165,14 +1165,14 @@ actual arch. # compute default tag = node.tag - parent = node.getparent() + had_parent = node.getparent() is not None node_info = dict(root_info, modifiers={}, editable=editable and self._editable_node(node, name_manager)) # tag-specific postprocessing postprocessor = getattr(self, f"_postprocess_tag_{tag}", None) if postprocessor is not None: postprocessor(node, name_manager, node_info) - if node.getparent() is not parent: + if had_parent and node.getparent() is None: # the node has been removed, stop processing here continue diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index a3e6952404d..92aaeb2da7e 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -2880,6 +2880,28 @@ class TestViews(ViewCase): """, valid=True) + def test_attrs_groups_with_groups_in_model(self): + """Tests the attrs is well processed to modifiers for a field node combining: + - a `groups` attribute on the field node in the view architecture + - a `groups` attribute on the field in the Python model + This is an edge case and it worths a unit test.""" + self.patch(type(self.env['res.partner']).name, 'groups', 'base.group_system') + self.env.user.groups_id += self.env.ref('base.group_multi_company') + view = self.View.create({ + 'name': 'foo', + 'model': 'res.partner', + 'arch': """ +
+ + + + """, + }) + arch = self.env['res.partner'].get_view(view_id=view.id)['arch'] + tree = etree.fromstring(arch) + node_field_name = tree.xpath('//field[@name="name"]')[0] + self.assertEqual(node_field_name.get('modifiers'), '{"invisible": [["active", "=", true]]}') + def test_button(self): arch = """