[FIX] website_theme_install: do not write view arch if it was modified

During theme install, theme.ir.ui.view are copied as ir.ui.view for the
requested website.
During theme update, those already created ir.ui.view will receive the
theme.ir.ui.view modifications, including the `arch`, even if it was changed by
the user, meaning the user changes would be lost.

Here are some examples which will be wiped away when the theme
is updated (only if the view is loaded from the theme module):

- Changes made from website HTML/CSS/JS editor.
- Changes made from website builder e.g. Theme modify footer with XPath
  and user make changes in footer then user changes will be gone on theme update
- Changes made directly in the arch of ir.ui.view in the backend.

This commit fixes that behavior by not updating views which were modified by
the user.

closes odoo/odoo#49224

X-original-commit: 9906e1d403c4e9137a0313c342a455f425e95b8e
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
Co-authored-by: Romain Derie <rde@odoo.com>
Co-authored-by: Kishan Gajjar <kishanegajjar@gmail.com>
This commit is contained in:
Romain Derie
2020-04-08 12:15:25 +00:00
co-authored by Kishan Gajjar
parent 637a591c05
commit babbe363b6
2 changed files with 10 additions and 0 deletions
@@ -162,6 +162,8 @@ class IrModuleModule(models.Model):
# at update, ignore active field
if 'active' in rec_data:
rec_data.pop('active')
if model_name == 'ir.ui.view' and (find.arch_updated or find.arch == rec_data['arch']):
rec_data.pop('arch')
find.update(rec_data)
self._post_copy(rec, find)
else:
+8
View File
@@ -1309,3 +1309,11 @@ class TestThemeViews(common.TransactionCase):
specific_main_view_children = specific_main_view.inherit_children_ids
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
new_arch = '<xpath expr="//body" position="replace"><span>Odoo</span></xpath>'
specific_main_view_children.arch = new_arch
theme_view.name = 'Test Child View modified'
test_theme_module.with_context(load_all_views=True)._theme_load(website_1)
self.assertEqual(specific_main_view_children.arch, new_arch, "View arch shouldn't have been overrided on theme update as it was modified by user.")
self.assertEqual(specific_main_view_children.name, 'Test Child View modified', "View should receive modification on theme update.")