[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) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2020-11-04 11:31:54 +00:00
parent c1e0b03d8b
commit b761191446
2 changed files with 27 additions and 3 deletions
+3 -3
View File
@@ -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))
+24
View File
@@ -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': """
<data>
<world t-field="a" position="replace">
<world t-field="z"/>
</world>
</data>
"""
})
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",