[FIX] website_theme_install: properly reset config on theme change

Before this commit, some code was resetting some default website config
on theme change.

Problem 1:
This was not done when *removing* a theme. Thus when you wanted to go
back to a default website theme, you were not properly reset to the
default theme config. This could actually crash: some themes define
more fonts than others; so if you selected font 13 in one theme then
removed the theme, the default one would crash if not properly reset
as font 13 would not exist.

Problem 2:
It was done for every theme dependency, making theme change slower for
no reason.

Problem 3 (theorically, not tested):
The current code worked by chance as it called the website
'make_scss_customization' method without giving any website to it. It
actually worked by fallback on the right website in normal user cases
(user in the context of installing a theme on a specific website) but
may not be working when trying to install a theme on a different website
calling those functions from custom code.

Now, a dedicated method is there for config reset and is called at the
correct place with the right website in the context.

closes odoo/odoo#53743

X-original-commit: 7307d696449ea2b7a231b0b9087e64f6bbf65d26
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2020-06-26 14:00:44 +00:00
parent e8dfbbd1c4
commit f7ff02b0fb
2 changed files with 15 additions and 8 deletions
@@ -325,6 +325,11 @@ class IrModuleModule(models.Model):
:param website: ``website`` model for which the themes have to be removed
"""
# _theme_remove is the entry point of any change of theme for a website
# (either removal or installation of a theme and its dependencies). In
# either case, we need to reset some default configuration before.
self.env['theme.utils'].with_context(website_id=website.id)._reset_default_config()
if not website.theme_id:
return
+10 -8
View File
@@ -153,6 +153,16 @@ class Theme(models.AbstractModel):
_auto = False
def _post_copy(self, mod):
# Call specific theme post copy
theme_post_copy = '_%s_post_copy' % mod.name
if hasattr(self, theme_post_copy):
_logger.info('Executing method %s' % theme_post_copy)
method = getattr(self, theme_post_copy)
return method(mod)
return False
@api.model
def _reset_default_config(self):
# Reinitialize some css customizations
self.env['web_editor.assets'].make_scss_customization(
'/website/static/src/scss/options/user_values.scss',
@@ -179,14 +189,6 @@ class Theme(models.AbstractModel):
self.disable_view('website.template_footer_logo_only')
self.disable_view('website.template_footer_address_logo')
# Call specific theme post copy
theme_post_copy = '_%s_post_copy' % mod.name
if hasattr(self, theme_post_copy):
_logger.info('Executing method %s' % theme_post_copy)
method = getattr(self, theme_post_copy)
return method(mod)
return False
@api.model
def _toggle_view(self, xml_id, active):
obj = self.env.ref(xml_id)