From aa468fe0b61e95b6197100b0b72c0fdd53ccdfa7 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 11 May 2022 08:58:47 +0000 Subject: [PATCH] [FIX] base: remove branding on nodes whose inner content is removed Parent view: ``` ``` Child view: ``` ``` => There are two in the original view, the first one is removed by a child view. In that case, the branding was still distributed on the element. This is a problem as it meant that in edit mode you were able to edit the whole content of that element... breaking the xpath made by the child view. After this commit, in that case, the branding is rightfully distributed on the remaining 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) --- odoo/addons/base/models/ir_ui_view.py | 3 ++ odoo/addons/base/tests/test_views.py | 42 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index fefd9d9d2a3..fd397da7215 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -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 diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index 7ad8a1f9442..12d2e887752 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -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': """ + + + + + """ + }) + self.View.create({ + 'name': "Extension", + 'type': 'qweb', + 'inherit_id': view1.id, + 'arch': """ + + + + """ + }) + + 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 + # 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",