[FIX] website: stop calling theme _post_copy() on theme update

Before this commit, both the theme install* and upgrade flow would end
up calling the theme's `_post_copy()`.
The `_post_copy()` is in charge of enabling or disabling some website
options as ripple effect, language in footer, changing header template
etc.

From there, the user could later fine-tune its website and change those
options, altering what the theme chose during the install.

We don't want a later theme update to reapply the theme pre-selected
options and erase/revert the changes the user made after the theme
install.

This commit is then removing the call to `_post_copy()` on theme update.

Note that the `_post_copy()` is encapsulating the theme python code
which is supposed to only do some visual stuff like enabling a view or a
theme option.

Also, note that calling `_post_copy()` in a theme update will not only
re-enable/disable some views but that will create a de-sync between the
activated view and the scss value.
Indeed, for instance, enabling the hamburger menu view is not enough, it
should also be coming with a scss value change.
The mismatch between the template and the scss will lead to some visual
glitches / ugly result.
Calling `_post_copy()` when applying the theme for the first time
through the UI (the only way possible) will not create that de-sync
issue as that flow is resetting the scss value:
`_reset_default_config()` will be called through `_theme_remove()`.

* `theme install` does not refer to the module install
  but the moment the theme is applied on a website, which is not the
  same as themes modules behaves in their own manner. When a theme is
  installed on the DB, it does nothing except creating fake records in
  "standalone" tables, which will then be converted to real records and
  applied on the selected website.

opw-2824045

closes odoo/odoo#93109

X-original-commit: 14387f36438b731753e2e7169f54865b123cdcfa
Related: odoo/design-themes#571
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Romain Derie
2022-06-08 16:50:56 +02:00
parent 5acddcd304
commit bed3cd54a5
+14 -1
View File
@@ -75,6 +75,9 @@ class IrModuleModule(models.Model):
-> We want to upgrade every website using this theme.
"""
if request and request.context.get('apply_new_theme'):
self = self.with_context(apply_new_theme=True)
for module in self:
if module.name.startswith('theme_') and vals.get('state') == 'installed':
_logger.info('Module %s has been loaded as theme template (%s)' % (module.name, module.state))
@@ -207,7 +210,15 @@ class IrModuleModule(models.Model):
for model_name in self._theme_model_names:
module._update_records(model_name, website)
self.env['theme.utils'].with_context(website_id=website.id)._post_copy(module)
if self._context.get('apply_new_theme'):
# Both the theme install and upgrade flow ends up here.
# The _post_copy() is supposed to be called only when the theme
# is installed for the first time on a website.
# It will basically select some header and footer template.
# We don't want the system to select again the theme footer or
# header template when that theme is updated later. It could
# erase the change the user made after the theme install.
self.env['theme.utils'].with_context(website_id=website.id)._post_copy(module)
def _theme_unload(self, website):
"""
@@ -361,6 +372,8 @@ class IrModuleModule(models.Model):
website.theme_id = self
# this will install 'self' if it is not installed yet
if request:
request.update_context(apply_new_theme=True)
self._theme_upgrade_upstream()
active_todo = self.env['ir.actions.todo'].search([('state', '=', 'open')], limit=1)