[FIX] website_theme_install: properly attach new views to specific views
When a theme declares a view (a 'theme.ir.ui.view') with an inherit_id, on installation, a view (a 'ir.ui.view') will be created with the corresponding inherit_id. The problem is that this inherit_id may reference a view that has been cow'ed at some point and thus the new theme view will be attached to the non specific view by mistake. Part of https://github.com/odoo/odoo/pull/37142 closes odoo/odoo#37750 X-original-commit: https://github.com/odoo/odoo/commit/f30b4dfdb90515bc54e691302f894184c9b1c55b Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Co-authored-by: Romain Derie <rde@odoo.com>
This commit is contained in:
committed by
qsm-odoo
co-authored by
Romain Derie
parent
eded0294ab
commit
b77d8a0974
@@ -189,7 +189,6 @@ class IrModuleModule(models.Model):
|
||||
ON CONFLICT DO NOTHING""",
|
||||
(dst_field, new_rec.id, src_field, old_rec.id))
|
||||
|
||||
|
||||
def _theme_load(self, website):
|
||||
"""
|
||||
For every type of model in ``self._theme_model_names``, and for every theme in ``self``:
|
||||
|
||||
@@ -40,6 +40,14 @@ class ThemeView(models.Model):
|
||||
# inherit_id not yet created, add to the queue
|
||||
return False
|
||||
|
||||
if inherit and inherit.website_id != website:
|
||||
website_specific_inherit = self.env['ir.ui.view'].with_context(active_test=False).search([
|
||||
('key', '=', inherit.key),
|
||||
('website_id', '=', website.id)
|
||||
], limit=1)
|
||||
if website_specific_inherit:
|
||||
inherit = website_specific_inherit
|
||||
|
||||
new_view = {
|
||||
'type': self.type or 'qweb',
|
||||
'name': self.name,
|
||||
|
||||
@@ -1,7 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import HttpCase
|
||||
from odoo.tests import HttpCase, tagged, TransactionCase
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestViews(TransactionCase):
|
||||
def test_inherit_specific(self):
|
||||
View = self.env['ir.ui.view']
|
||||
Website = self.env['website']
|
||||
|
||||
website_1 = Website.create({'name': 'Website 1'})
|
||||
|
||||
# 1. Simulate COW structure
|
||||
main_view = View.create({
|
||||
'name': 'Test Main View',
|
||||
'type': 'qweb',
|
||||
'arch': '<body>Arch is not relevant for this test</body>',
|
||||
'key': '_test.main_view',
|
||||
}).with_context(load_all_views=True)
|
||||
# Trigger COW
|
||||
main_view.with_context(website_id=website_1.id).arch = '<body>specific</body>'
|
||||
|
||||
# 2. Simulate a theme install with a child view of `main_view`
|
||||
test_theme_module = self.env['ir.module.module'].create({'name': 'test_theme'})
|
||||
self.env['ir.model.data'].create({
|
||||
'module': 'base',
|
||||
'name': 'module_test_theme_module',
|
||||
'model': 'ir.module.module',
|
||||
'res_id': test_theme_module.id,
|
||||
})
|
||||
theme_view = self.env['theme.ir.ui.view'].with_context(install_filename='/testviews').create({
|
||||
'name': 'Test Child View',
|
||||
'mode': 'extension',
|
||||
'inherit_id': 'ir.ui.view,%s' % main_view.id,
|
||||
'arch': '<xpath expr="//body" position="replace"><span>C</span></xpath>',
|
||||
'key': 'test_theme.test_child_view',
|
||||
})
|
||||
self.env['ir.model.data'].create({
|
||||
'module': 'test_theme',
|
||||
'name': 'products',
|
||||
'model': 'theme.ir.ui.view',
|
||||
'res_id': theme_view.id,
|
||||
})
|
||||
test_theme_module.with_context(load_all_views=True)._theme_load(website_1)
|
||||
|
||||
# 3. Ensure everything went correctly
|
||||
main_views = View.search([('key', '=', '_test.main_view')])
|
||||
self.assertEqual(len(main_views), 2, "View should have been COWd when writing on its arch in a website context")
|
||||
specific_main_view = main_views.filtered(lambda v: v.website_id == website_1)
|
||||
specific_main_view_children = specific_main_view.inherit_children_ids
|
||||
self.assertEqual(specific_main_view_children.name, 'Test Child View', "Ensure theme.ir.ui.view has been loaded as an ir.ui.view into the website..")
|
||||
self.assertEqual(specific_main_view_children.website_id, website_1, "..and the website is the correct one.")
|
||||
|
||||
|
||||
class Crawler(HttpCase):
|
||||
|
||||
Reference in New Issue
Block a user