diff --git a/addons/website/models/theme_models.py b/addons/website/models/theme_models.py index 566da645e27..2b0c8f321bf 100644 --- a/addons/website/models/theme_models.py +++ b/addons/website/models/theme_models.py @@ -222,6 +222,20 @@ class IrUiView(models.Model): theme_template_id = fields.Many2one('theme.ir.ui.view') + def write(self, vals): + no_arch_updated_views = other_views = self.env['ir.ui.view'] + for record in self: + # Do not mark the view as user updated if original view arch is similar + arch = vals.get('arch', vals.get('arch_base')) + if record.theme_template_id and record.theme_template_id.arch == arch: + no_arch_updated_views += record + else: + other_views += record + res = super(IrUiView, other_views).write(vals) + if no_arch_updated_views: + vals['arch_updated'] = False + res &= super(IrUiView, no_arch_updated_views).write(vals) + return res class IrAttachment(models.Model): _inherit = 'ir.attachment' diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index c662416756c..61415064eed 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -1310,7 +1310,18 @@ class TestThemeViews(common.TransactionCase): 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.") - # 4. Keep User arch changes + # 4. Simulate theme update. Do it 2 time to make sure it was not interpreted as a user change the first time. + new_arch = 'Odoo Change01' + theme_view.arch = new_arch + test_theme_module.with_context(load_all_views=True)._theme_load(website_1) + self.assertEqual(specific_main_view_children.arch, new_arch, "First time: View arch should receive theme updates.") + self.assertFalse(specific_main_view_children.arch_updated) + new_arch = 'Odoo Change02' + theme_view.arch = new_arch + test_theme_module.with_context(load_all_views=True)._theme_load(website_1) + self.assertEqual(specific_main_view_children.arch, new_arch, "Second time: View arch should still receive theme updates.") + + # 5. Keep User arch changes new_arch = 'Odoo' specific_main_view_children.arch = new_arch theme_view.name = 'Test Child View modified' diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py index bbd5b6cd97e..b4d0ea7f2c5 100644 --- a/odoo/addons/base/models/ir_ui_view.py +++ b/odoo/addons/base/models/ir_ui_view.py @@ -478,7 +478,7 @@ actual arch. def write(self, vals): # Keep track if view was modified. That will be useful for the --dev mode # to prefer modified arch over file arch. - if ('arch' in vals or 'arch_base' in vals) and 'install_filename' not in self._context: + if 'arch_updated' not in vals and ('arch' in vals or 'arch_base' in vals) and 'install_filename' not in self._context: vals['arch_updated'] = True # drop the corresponding view customizations (used for dashboards for example), otherwise