[FIX] web_editor: fix oe_structure view that are not in extention mode

Issue occurs due to the way we compute the default value in base ir ui view.
The method _compute_defaults don't set extention mode under some condition
even if we provide an inherit_id view.

This commit double fix it, we use now self.env['ir.ui.view'] to create the
new view and so always compute the mode based on 'if inherit id or not'.
Second fixes is to explicitely set mode manually as 'extention'.

before commit:
when you drop snippet to blog sidebar and click save button.
The changes of user is not visible in sidebar because view created in mode
'normal' and not 'extention'

task-2311520
closes odoo/odoo#55908

closes odoo/odoo#59318

X-original-commit: a944ce9beaaf984a7b1282785d03d4bfc8220f18
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Co-authored-by: jpr-odoo <jpr@openerp.com>
This commit is contained in:
Harpritsinh Sisodiya
2020-10-06 16:35:59 +00:00
committed by Jeremy Kersten
co-authored by jpr-odoo
parent 7076449752
commit 7c3cb51e52
2 changed files with 47 additions and 9 deletions
+2 -1
View File
@@ -82,9 +82,10 @@ class IrUiView(models.Model):
'arch': self._pretty_arch(arch),
'key': '%s_%s' % (self.key, el.get('id')),
'type': 'qweb',
'mode': 'extension',
}
vals.update(self._save_oe_structure_hook())
self.create(vals)
self.env['ir.ui.view'].create(vals)
return True
+45 -8
View File
@@ -5,23 +5,60 @@ from odoo.tests import TransactionCase
class TestViews(TransactionCase):
def test_infinite_inherit_loop(self):
# Creates an infinite loop: A t-call B and A inherit from B
def setUp(self):
super().setUp()
View = self.env['ir.ui.view']
first_view = View.create({
self.first_view = View.create({
'name': 'Test View 1',
'type': 'qweb',
'arch': '<div>Hello World</div>',
'key': 'web_editor.test_first_view',
})
second_view = View.create({
self.second_view = View.create({
'name': 'Test View 2',
'type': 'qweb',
'arch': '<t t-call="web_editor.test_first_view"/>',
'arch': '<div><t t-call="web_editor.test_first_view"/></div>',
'key': 'web_editor.test_second_view',
})
second_view.write({
'inherit_id': first_view.id,
def test_infinite_inherit_loop(self):
# Creates an infinite loop: A t-call B and A inherit from B
View = self.env['ir.ui.view']
self.second_view.write({
'inherit_id': self.first_view.id,
})
# Test for RecursionError: maximum recursion depth exceeded in this function
View._views_get(first_view)
View._views_get(self.first_view)
def test_oe_structure_as_inherited_view(self):
View = self.env['ir.ui.view']
base = View.create({
'name': 'Test View oe_structure',
'type': 'qweb',
'arch': """<xpath expr='//t[@t-call="web_editor.test_first_view"]' position='after'>
<div class="oe_structure" id='oe_structure_test_view_oe_structure'/>
</xpath>""",
'key': 'web_editor.oe_structure_view',
'inherit_id': self.second_view.id
})
# check view mode
self.assertEqual(base.mode, 'extension')
# update content of the oe_structure
value = '''<div class="oe_structure" id="oe_structure_test_view_oe_structure" data-oe-id="%s"
data-oe-xpath="/div" data-oe-model="ir.ui.view" data-oe-field="arch">
<p>Hello World!</p>
</div>''' % base.id
base.save(value=value, xpath='/xpath/div')
self.assertEqual(len(base.inherit_children_ids), 1)
self.assertEqual(base.inherit_children_ids.mode, 'extension')
self.assertIn(
'<p>Hello World!</p>',
base.inherit_children_ids.read_combined(['arch'])['arch'],
)