[FIX] qweb: render of a primary view
Revisions [1] and [2] broke the rendering of extensions-primary view because it made the wrong assumption that the `read_template` of an extension-primary view set the `t-name` attribute to the name of the extension-primary view. We now patch the `t-name` in the `read_template` result for this case. [1]12e36a66f2[2]9dd5bd9349
This commit is contained in:
@@ -83,11 +83,11 @@ class IrQWeb(models.AbstractModel, QWeb):
|
||||
# QWeb's `read_template` will check if one of the first children of
|
||||
# what we send to it has a "t-name" attribute having `name` as value
|
||||
# to consider it has found it. As it'll never be the case when working
|
||||
# with view ids or children view, force it here.
|
||||
def is_child_view(view):
|
||||
view_id = self.env['ir.ui.view'].get_view_id(name)
|
||||
# with view ids or children view or children primary views, force it here.
|
||||
def is_child_view(view_name):
|
||||
view_id = self.env['ir.ui.view'].get_view_id(view_name)
|
||||
view = self.env['ir.ui.view'].browse(view_id)
|
||||
return view.inherit_id is not None and view.mode != 'primary'
|
||||
return view.inherit_id is not None
|
||||
|
||||
if isinstance(name, (int, long)) or is_child_view(name):
|
||||
for node in etree.fromstring(template):
|
||||
|
||||
@@ -1207,14 +1207,25 @@ class TestQWebRender(ViewCase):
|
||||
</xpath>
|
||||
"""
|
||||
})
|
||||
view3 = self.View.create({
|
||||
'name': "dummy_primary_ext",
|
||||
'type': 'qweb',
|
||||
'inherit_id': view1.id,
|
||||
'mode': 'primary',
|
||||
'arch': """
|
||||
<xpath expr="//div" position="inside">
|
||||
<span>another primary thing</span>
|
||||
</xpath>
|
||||
"""
|
||||
})
|
||||
|
||||
# render with an id
|
||||
# render view and child view with an id
|
||||
content1 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id]).render(view1.id)
|
||||
content2 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id]).render(view2.id)
|
||||
|
||||
self.assertEqual(content1, content2)
|
||||
|
||||
# render with an xmlid
|
||||
# render view and child view with an xmlid
|
||||
self.env.cr.execute("INSERT INTO ir_model_data(name, model, res_id, module)"
|
||||
"VALUES ('dummy', 'ir.ui.view', %s, 'base')" % view1.id)
|
||||
self.env.cr.execute("INSERT INTO ir_model_data(name, model, res_id, module)"
|
||||
@@ -1224,3 +1235,18 @@ class TestQWebRender(ViewCase):
|
||||
content2 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id]).render('base.dummy_ext')
|
||||
|
||||
self.assertEqual(content1, content2)
|
||||
|
||||
# render view and primary extension with an id
|
||||
content1 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id, view3.id]).render(view1.id)
|
||||
content3 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id, view3.id]).render(view3.id)
|
||||
|
||||
self.assertNotEqual(content1, content3)
|
||||
|
||||
# render view and primary extension with an xmlid
|
||||
self.env.cr.execute("INSERT INTO ir_model_data(name, model, res_id, module)"
|
||||
"VALUES ('dummy_primary_ext', 'ir.ui.view', %s, 'base')" % view3.id)
|
||||
|
||||
content1 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id, view3.id]).render('base.dummy')
|
||||
content3 = self.env['ir.qweb'].with_context(check_view_ids=[view1.id, view2.id, view3.id]).render('base.dummy_primary_ext')
|
||||
|
||||
self.assertNotEqual(content1, content3)
|
||||
Reference in New Issue
Block a user