[FIX] base: remove branding on nodes whose inner content is removed

Parent view:
```
<hello>
    <world></world>
    <world></world>
</hello>
```

Child view:
```
<data>
    <xpath expr="/hello/world[1]" position="replace"/>
</data>
```

=> There are two <world/> in the original view, the first one is removed
   by a child view.

In that case, the branding was still distributed on the <hello> element.
This is a problem as it meant that in edit mode you were able to edit
the whole content of that <hello/> element... breaking the xpath made by
the child view.
After this commit, in that case, the branding is rightfully distributed
on the remaining <world/> element (just like it would have been if the
inheriting view had added an element instead of just removing one).

This is a follow-up of the parent commit (of the same PR at [1]).

[1]: https://github.com/odoo/odoo/pull/91015

Related to opw-2811674

closes odoo/odoo#91991

X-original-commit: abd9d7a74c91f4632550a376fe566ac28e64377b
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
qsm-odoo
2022-05-20 22:05:47 +02:00
committed by Romain Derie
parent 89f9bb887a
commit aa468fe0b6
2 changed files with 45 additions and 0 deletions
+3
View File
@@ -1986,6 +1986,9 @@ actual arch.
return any(
(attr in ('data-oe-model', 'groups') or (attr.startswith('t-')))
for attr in node.attrib
) or (
node.tag is etree.ProcessingInstruction
and node.target == 'apply-inheritance-specs-node-removal'
)
@api.model
+42
View File
@@ -908,6 +908,48 @@ class TestTemplating(ViewCase):
initial.get('data-oe-xpath'),
"The node's xpath position should be correct")
def test_branding_inherit_remove_node2(self):
view1 = self.View.create({
'name': "Base view",
'type': 'qweb',
'arch': """
<hello>
<world></world>
<world></world>
</hello>
"""
})
self.View.create({
'name': "Extension",
'type': 'qweb',
'inherit_id': view1.id,
'arch': """
<data>
<xpath expr="/hello/world[1]" position="replace"/>
</data>
"""
})
arch_string = view1.with_context(inherit_branding=True).get_combined_arch()
arch = etree.fromstring(arch_string)
self.View.distribute_branding(arch)
# Note: this test is a variant of the test_branding_inherit_remove_node
# -> in this case, we expect the branding to not be distributed on the
# <hello/> element anymore but on the only remaining world.
[initial] = arch.xpath('/hello[1]')
self.assertIsNone(
initial.get('data-oe-model'),
"The inner content of the root was xpath'ed, it should not receive branding anymore")
# Only remaining world but still the second in original view
[initial] = arch.xpath('/hello[1]/world[1]')
self.assertEqual(
'/hello[1]/world[2]',
initial.get('data-oe-xpath'),
"The node's xpath position should be correct")
def test_branding_inherit_top_t_field(self):
view1 = self.View.create({
'name': "Base view",