[FIX] website_theme_install, base: fix theme update

When a theme module is updated the changes made on a view are considered
as user changes, prenventing the view from being updated in the future.

Fixed by comparing the arch being written with the arch of the original
view. If it is the same the record should not be noupdate.
Plus added a test to make sure the theme views receive theme updates
after being updated once.

Introduced by: https://github.com/odoo/odoo/commit/4acf177b4c55f3a16362cbeafea3d332ef4fe819

closes odoo/odoo#51557

X-original-commit: 221470ab9c9eda3f3a4e2da0fa1a7bb23d6288cc
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
fja-odoo
2020-05-19 15:42:55 +00:00
parent 8adaaf5074
commit 1eb7c577ec
3 changed files with 27 additions and 2 deletions
+14
View File
@@ -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'
+12 -1
View File
@@ -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 = '<xpath expr="//body" position="replace"><span>Odoo Change01</span></xpath>'
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 = '<xpath expr="//body" position="replace"><span>Odoo Change02</span></xpath>'
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 = '<xpath expr="//body" position="replace"><span>Odoo</span></xpath>'
specific_main_view_children.arch = new_arch
theme_view.name = 'Test Child View modified'
+1 -1
View File
@@ -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