[FIX] theme_*: enable footer/header template correctly
Some theme are enabling an header template. When doing so, they also disable the default header template. But this is not enough, as the user could have changed that template and it is not the default one anymore. Then, updating that theme (UX, CLI, Migration) will raise a traceback. Step to reproduce: - Create a website and install theme avantgarde - Enter edit mode and select Magazine header template At that point, update the theme, either: - Through the UI, on theme switch screen, click on Update - Through CLI, just run a `-u theme_avantgarde` -> A traceback will be raised about an xpath error, as both the magazine header template and the hamburger header template are active at the same time. Only one template is supposed to be activated. The issue also impact migration, as migrated website can't be accessed due to the xpath error on rendering. Theme being impacted (at least): Avantgarde, Graphene & Nano Note that when installing one of those themes for the first time on a website, the error won't occur as `_reset_default_config()` will be called through `_theme_remove()`. Note that this fix will ensure the correct template is set (and all others are disabled), but the scss variable won't be correctly set (as it would be if that template change was done through the right panel). This is not that much of a problem (considering what it solves), any later change from the user through the right panel will solve that mismatch. Fixes https://github.com/odoo/upgrade/pull/3048 task-2593407 opw-2680866 opw-2685951 opw-2685124 opw-2679040 X-original-commit: f18cd32a936829d8a059db0d259189503ee5317f Part-of: odoo/odoo#81953
This commit is contained in:
@@ -192,6 +192,32 @@ class Theme(models.AbstractModel):
|
||||
_description = 'Theme Utils'
|
||||
_auto = False
|
||||
|
||||
_header_templates = [
|
||||
'website.template_header_hamburger',
|
||||
'website.template_header_vertical',
|
||||
'website.template_header_sidebar',
|
||||
'website.template_header_slogan',
|
||||
'website.template_header_contact',
|
||||
'website.template_header_boxed',
|
||||
'website.template_header_centered_logo',
|
||||
'website.template_header_image',
|
||||
'website.template_header_hamburger_full',
|
||||
'website.template_header_magazine',
|
||||
# Default one, keep it last
|
||||
'website.template_header_default',
|
||||
]
|
||||
_footer_templates = [
|
||||
'website.template_footer_descriptive',
|
||||
'website.template_footer_centered',
|
||||
'website.template_footer_links',
|
||||
'website.template_footer_minimalist',
|
||||
'website.template_footer_contact',
|
||||
'website.template_footer_call_to_action',
|
||||
'website.template_footer_headline',
|
||||
# Default one, keep it last
|
||||
'website.footer_custom',
|
||||
]
|
||||
|
||||
def _post_copy(self, mod):
|
||||
# Call specific theme post copy
|
||||
theme_post_copy = '_%s_post_copy' % mod.name
|
||||
@@ -225,27 +251,14 @@ class Theme(models.AbstractModel):
|
||||
self.disable_asset("website.ripple_effect_js")
|
||||
|
||||
# Reinitialize header templates
|
||||
self.disable_view('website.template_header_hamburger')
|
||||
self.disable_view('website.template_header_vertical')
|
||||
self.disable_view('website.template_header_sidebar')
|
||||
self.disable_view('website.template_header_slogan')
|
||||
self.disable_view('website.template_header_contact')
|
||||
self.disable_view('website.template_header_boxed')
|
||||
self.disable_view('website.template_header_centered_logo')
|
||||
self.disable_view('website.template_header_image')
|
||||
self.disable_view('website.template_header_hamburger_full')
|
||||
self.disable_view('website.template_header_magazine')
|
||||
self.enable_view('website.template_header_default')
|
||||
for view in self._header_templates[:-1]:
|
||||
self.disable_view(view)
|
||||
self.enable_view(self._header_templates[-1])
|
||||
|
||||
# Reinitialize footer templates
|
||||
self.disable_view('website.template_footer_descriptive')
|
||||
self.disable_view('website.template_footer_centered')
|
||||
self.disable_view('website.template_footer_links')
|
||||
self.disable_view('website.template_footer_minimalist')
|
||||
self.disable_view('website.template_footer_contact')
|
||||
self.disable_view('website.template_footer_call_to_action')
|
||||
self.disable_view('website.template_footer_headline')
|
||||
self.enable_view('website.footer_custom')
|
||||
for view in self._footer_templates[:-1]:
|
||||
self.disable_view(view)
|
||||
self.enable_view(self._footer_templates[-1])
|
||||
|
||||
# Reinitialize footer scrolltop template
|
||||
self.disable_view('website.option_footer_scrolltop')
|
||||
@@ -300,6 +313,12 @@ class Theme(models.AbstractModel):
|
||||
|
||||
@api.model
|
||||
def enable_view(self, xml_id):
|
||||
if xml_id in self._header_templates:
|
||||
for view in self._header_templates:
|
||||
self.disable_view(view)
|
||||
elif xml_id in self._footer_templates:
|
||||
for view in self._footer_templates:
|
||||
self.disable_view(view)
|
||||
self._toggle_view(xml_id, True)
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -12,3 +12,29 @@ class TestTheme(common.TransactionCase):
|
||||
website = self.env['website'].get_current_website()
|
||||
website.theme_id = theme_common_module.id
|
||||
self.env['ir.module.module']._theme_remove(website)
|
||||
|
||||
def test_02_disable_view(self):
|
||||
"""This test ensure only one template header can be active at a time."""
|
||||
website_id = self.env['website'].browse(1)
|
||||
ThemeUtils = self.env['theme.utils'].with_context(website_id=website_id.id)
|
||||
|
||||
ThemeUtils._reset_default_config()
|
||||
|
||||
def _get_header_template_key():
|
||||
return self.env['ir.ui.view'].search([
|
||||
('key', 'in', ThemeUtils._header_templates),
|
||||
('website_id', '=', website_id.id),
|
||||
]).key
|
||||
|
||||
self.assertEqual(_get_header_template_key(), 'website.template_header_default',
|
||||
"Only the default template should be active.")
|
||||
|
||||
key = 'website.template_header_magazine'
|
||||
ThemeUtils.enable_view(key)
|
||||
self.assertEqual(_get_header_template_key(), key,
|
||||
"Only one template can be active at a time.")
|
||||
|
||||
key = 'website.template_header_hamburger'
|
||||
ThemeUtils.enable_view(key)
|
||||
self.assertEqual(_get_header_template_key(), key,
|
||||
"Ensuring it works also for non default template.")
|
||||
|
||||
Reference in New Issue
Block a user