summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfja-odoo <fja@odoo.com>2020-05-18 10:51:30 +0000
committerfja-odoo <fja@odoo.com>2020-05-19 15:42:55 +0000
commit1eb7c577ecb31c2f0876b6dd76769e2b47802cb0 (patch)
tree94f6dbb457ed56dfdaaeef1c66cb19b772ca48b1
parent8adaaf50741c460122ce111bfd676538c1577bb9 (diff)
[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>
-rw-r--r--addons/website/models/theme_models.py14
-rw-r--r--addons/website/tests/test_views.py13
-rw-r--r--odoo/addons/base/models/ir_ui_view.py2
3 files changed, 27 insertions, 2 deletions
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 = '<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'
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