diff --git a/addons/website/models/ir_module_module.py b/addons/website/models/ir_module_module.py index a563a9efa85..1073b384d81 100644 --- a/addons/website/models/ir_module_module.py +++ b/addons/website/models/ir_module_module.py @@ -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)