diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index 9f89b7af687..d606ad56770 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -692,7 +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.tag == 'data' or node.tag == 'xpath' or node.get('position') or node.get('t-field'): + if node.get('t-field'): + node.set('data-oe-xpath', xpath) + self.inherit_branding(node) + elif node.tag == 'data' or node.tag == 'xpath' or node.get('position'): self.inherit_branding(node) else: node.set('data-oe-id', str(self.id)) @@ -1628,9 +1631,12 @@ actual arch. node_path = e.get('data-oe-xpath') if node_path is None: node_path = "%s/%s[%d]" % (parent_xpath, e.tag, index_map[e.tag]) - if branding and not (e.get('data-oe-model') or e.get('t-field')): - e.attrib.update(branding) - e.set('data-oe-xpath', node_path) + if branding: + if e.get('t-field'): + e.set('data-oe-xpath', node_path) + elif not e.get('data-oe-model'): + e.attrib.update(branding) + e.set('data-oe-xpath', node_path) if not e.get('data-oe-model'): return diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index ba6a3ec5e05..1633ec23dc4 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -808,6 +808,55 @@ class TestTemplating(ViewCase): 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", + 'type': 'qweb', + 'arch': """ + + + + + + + """ + }) + 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) + + # First t-field should have an indication of xpath + [node] = arch.xpath('//*[@t-field="a"]') + self.assertEqual( + node.get('data-oe-xpath'), + '/hello[1]/world[2]', + 'First t-field has indication of xpath') + + # Second t-field, from inheritance, should also have an indication of xpath + [node] = arch.xpath('//*[@t-field="b"]') + self.assertEqual( + node.get('data-oe-xpath'), + '/xpath/world', + 'Inherited t-field has indication of xpath') + + # The most important assert + # The last world xpath should not have been impacted by the t-field from inheritance + [node] = arch.xpath('//world[last()]') + self.assertEqual( + node.get('data-oe-xpath'), + '/hello[1]/world[4]', + "The node's xpath position should be correct") + def test_branding_primary_inherit(self): view1 = self.View.create({ 'name': "Base view",