From 198640434f9a94061148178beabbdbaae6f6711d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 24 Feb 2014 18:03:01 +0100 Subject: [PATCH] [FIX] injected views need branding distribution too forgot to set it up after installed injected view skipping during distribution of injectee bzr revid: xmo@openerp.com-20140224170301-b4ta04zqsd5d2956 --- openerp/addons/base/ir/ir_ui_view.py | 11 ++-- openerp/addons/base/tests/test_views.py | 67 ++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index d4655bf8b9c..da2618ea8f5 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -760,11 +760,12 @@ class view(osv.osv): if child.get('data-oe-xpath'): # injected by view inheritance, skip otherwise # generated xpath is incorrect - continue - indexes[child.tag] += 1 - self.distribute_branding(child, distributed_branding, - parent_xpath=node_path, - index_map=indexes) + self.distribute_branding(child) + else: + indexes[child.tag] += 1 + self.distribute_branding( + child, distributed_branding, + parent_xpath=node_path, index_map=indexes) def is_node_branded(self, node): """ Finds out whether a node is branded or qweb-active (bears a diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py index 6780996ed6e..d8b4298d4f0 100644 --- a/openerp/addons/base/tests/test_views.py +++ b/openerp/addons/base/tests/test_views.py @@ -473,6 +473,72 @@ class TestTemplating(common.TransactionCase): second.get('data-oe-id'), "second should come from the extension view") + def test_branding_distribute_inner(self): + """ Checks that the branding is correctly distributed within a view + extension + """ + Views = self.registry('ir.ui.view') + id = Views.create(self.cr, self.uid, { + 'name': "Base view", + 'type': 'qweb', + 'arch': """ + + """ + }) + id2 = Views.create(self.cr, self.uid, { + 'name': "Extension", + 'type': 'qweb', + 'inherit_id': id, + 'arch': """ + + bar + + """ + }) + + arch_string = Views.read_combined( + self.cr, self.uid, id, fields=['arch'], + context={'inherit_branding': True})['arch'] + + arch = ET.fromstring(arch_string) + Views.distribute_branding(arch) + + self.assertTreesEqual( + arch, + E.root( + E.item( + E.content("bar", { + 't-att-href': "foo", + 'data-oe-model': 'ir.ui.view', + 'data-oe-id': str(id2), + 'data-oe-field': 'arch', + 'data-oe-xpath': '/xpath/item/content[1]', + }), { + 'order': '2', + 'data-oe-source-id': "159" + }), + E.item({ + 'order': '1', + 'data-oe-model': 'ir.ui.view', + 'data-oe-id': str(id), + 'data-oe-field': 'arch', + 'data-oe-xpath': '/root[1]/item[1]' + }) + ) + ) + + def assertTreesEqual(self, n1, n2): + self.assertEqual(n1.tag, n2.tag) + self.assertEqual((n1.text or '').strip(), (n2.text or '').strip()) + self.assertEqual((n1.tail or '').strip(), (n2.tail or '').strip()) + + # Because lxml uses ordereddicts in which order is important to + # equality (!?!?!?!) + self.assertEqual(dict(n1.attrib), dict(n2.attrib)) + + for c1, c2 in zip(n1, n2): + self.assertTreesEqual(c1, c2) + class test_views(common.TransactionCase): def test_nonexistent_attribute_removal(self): @@ -666,4 +732,3 @@ class test_views(common.TransactionCase): '