summaryrefslogtreecommitdiff
path: root/addons/website_theme_install
diff options
context:
space:
mode:
authorfw-bot <otis@odoo.com>2019-10-01 22:46:39 +0000
committerqsm-odoo <qsm@odoo.com>2019-10-02 01:02:56 +0000
commitb77d8a0974962e36c437b339b1bb6aa14b3dd4a6 (patch)
tree34dc1d5da1b83d0f192694c6e7becc8648b06198 /addons/website_theme_install
parenteded0294ab1c5dfc6eb268f84d53ada9ba775352 (diff)
[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>
Diffstat (limited to 'addons/website_theme_install')
-rw-r--r--addons/website_theme_install/models/ir_module_module.py1
-rw-r--r--addons/website_theme_install/models/theme_models.py8
-rw-r--r--addons/website_theme_install/tests/test_views.py52
3 files changed, 59 insertions, 2 deletions
diff --git a/addons/website_theme_install/models/ir_module_module.py b/addons/website_theme_install/models/ir_module_module.py
index 316cb45331b..b9239df97e9 100644
--- a/addons/website_theme_install/models/ir_module_module.py
+++ b/addons/website_theme_install/models/ir_module_module.py
@@ -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``:
diff --git a/addons/website_theme_install/models/theme_models.py b/addons/website_theme_install/models/theme_models.py
index 965ead35d00..0c5da7e03f3 100644
--- a/addons/website_theme_install/models/theme_models.py
+++ b/addons/website_theme_install/models/theme_models.py
@@ -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,
diff --git a/addons/website_theme_install/tests/test_views.py b/addons/website_theme_install/tests/test_views.py
index 42be90dfbd5..2a660091a49 100644
--- a/addons/website_theme_install/tests/test_views.py
+++ b/addons/website_theme_install/tests/test_views.py
@@ -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):