From b76119144629df78bb7aea0e95ed92788f20fdfa Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 3 Nov 2020 10:44:45 +0000 Subject: [PATCH] [FIX] base: restore t-field inheritance via non-xpath node Commit [1] made a stupid mistake forgetting nodes with the t-field instruction can also have the position attribute in case of inheritance without xpath node. ... It did not crash because there actually is no case of it in the current codebase, but this is used by some custo on our prod however. The test introduced by mentioned commit has been extended to crash, should this specific case be broken again. [1]: https://github.com/odoo/odoo/commit/92ef3b2dd4655913198d10d06598b799fdcae6d0 closes odoo/odoo#61288 X-original-commit: b05c7f1e8054be4e74289ac366e0ddcc7da2228e Signed-off-by: Quentin Smetz (qsm) --- odoo/addons/base/models/ir_ui_view.py | 6 +++--- odoo/addons/base/tests/test_views.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index d606ad56770..5b3284de7bd 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -692,10 +692,10 @@ actual arch. def inherit_branding(self, specs_tree): for node in specs_tree.iterchildren(tag=etree.Element): xpath = node.getroottree().getpath(node) - if node.get('t-field'): - node.set('data-oe-xpath', xpath) + if node.tag == 'data' or node.tag == 'xpath' or node.get('position'): self.inherit_branding(node) - elif node.tag == 'data' or node.tag == 'xpath' or node.get('position'): + elif node.get('t-field'): + node.set('data-oe-xpath', xpath) self.inherit_branding(node) else: node.set('data-oe-id', str(self.id)) diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index 1633ec23dc4..77e26d75efc 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -857,6 +857,30 @@ class TestTemplating(ViewCase): '/hello[1]/world[4]', "The node's xpath position should be correct") + # Also test inherit via non-xpath t-field node, direct children of data, + # is not impacted by the feature + self.View.create({ + 'name': "Extension", + 'type': 'qweb', + 'inherit_id': view1.id, + 'arch': """ + + + + + + """ + }) + arch_string = view1.with_context(inherit_branding=True).read_combined(['arch'])['arch'] + arch = etree.fromstring(arch_string) + self.View.distribute_branding(arch) + + node = arch.xpath('//world')[1] + self.assertEqual( + node.get('t-field'), + 'z', + "The node has properly been replaced") + def test_branding_primary_inherit(self): view1 = self.View.create({ 'name': "Base view",