[FIX] base: continue stack post-processing after adding <t groups=

In a view, in the case of 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

e.g.
```py
name = fields.Char(groups='base.group_system')
```
```xml
<field name="name" groups="base.group_multi_company"/>
```

The view post-processing adds a temporary `<t groups` block.
e.g.
```xml
<t groups="base.group_system">
    <field name="base.group_multi_company"/>
</t>
```
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
<field name="name" groups="base.group_system,base.group_multi_company"/>
```
would be an `OR` connection, not an `AND.`
Hence this temporary added `<t groups=""`.

Before this revision, in such a case,
the stack post-processing was interrupted by an unexpected side-effect:
The field node changes of parent (the parent becomes that `t` block),
and a condition attempting to check that the node wasn't deleted from
the view actually checked that the parent changed, to decide to
interrupt the rest of the stack post-processing, including the modifiers
post-processing for that node.

This revision changes this behavior,
to check the field node no longer has a parent,
instead of a change of parent,
to decide that the node is indeed no longer in the view,
and to interrupt the stack post-processing or not.

This allow the field modifiers (e.g. `attrs=""`) to be post-processed
as expected.

opw-3072910

closes odoo/odoo#107173

X-original-commit: c163cbb6a9b3679067606868e325d9842ea66aa8
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
Denis Ledoux
2022-12-05 10:08:01 +01:00
parent 4e98f9902c
commit 51e12ca394
2 changed files with 24 additions and 2 deletions
+2 -2
View File
@@ -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
+22
View File
@@ -2880,6 +2880,28 @@ class TestViews(ViewCase):
</form>
""", 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': """
<form>
<field name="active"/>
<field name="name" groups="base.group_multi_company" attrs="{'invisible': [('active', '=', True)]}"/>
</form>
""",
})
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 = """
<form>