From e2f41d09ba7a5f2e6b0fa8efa1624e257824c992 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 May 2014 11:52:57 +0200 Subject: [PATCH] [IMP] prevent changing a view from application: always to application: disabled not sure that's actually useful, and can still go always -> enabled -> disabled... --- openerp/addons/base/ir/ir_ui_view.py | 8 +++++ openerp/addons/base/tests/test_views.py | 44 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index d006b02705c..de997b2cf36 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -258,6 +258,14 @@ class view(osv.osv): if custom_view_ids: self.pool.get('ir.ui.view.custom').unlink(cr, uid, custom_view_ids) + if vals.get('application') == 'disabled': + from_always = self.search( + cr, uid, [('id', 'in', ids), ('application', '=', 'always')], context=context) + if from_always: + raise ValueError( + "Can't disable views %s marked as always applied" % ( + ', '.join(map(str, from_always)))) + self.read_template.clear_cache(self) ret = super(view, self).write( cr, uid, ids, diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py index a098b9438ac..db9b475ddbe 100644 --- a/openerp/addons/base/tests/test_views.py +++ b/openerp/addons/base/tests/test_views.py @@ -1069,18 +1069,21 @@ class TestOptionalViews(ViewCase): 'model': 'a', 'inherit_id': self.v0, 'application': 'always', + 'priority': 10, 'arch': '', }) self.v2 = self.create({ 'model': 'a', 'inherit_id': self.v0, 'application': 'enabled', + 'priority': 9, 'arch': '', }) self.v3 = self.create({ 'model': 'a', 'inherit_id': self.v0, 'application': 'disabled', + 'priority': 8, 'arch': '' }) @@ -1097,6 +1100,47 @@ class TestOptionalViews(ViewCase): ) ) + def test_applied_state_toggle(self): + """ Change application states of v2 and v3, check that the results + are as expected + """ + self.browse(self.v2).write({'application': 'disabled'}) + arch = self.read_combined(self.v0)['arch'] + self.assertEqual( + ET.fromstring(arch), + E.qweb( + E.base(), + E.v1(), + ) + ) + + self.browse(self.v3).write({'application': 'enabled'}) + arch = self.read_combined(self.v0)['arch'] + self.assertEqual( + ET.fromstring(arch), + E.qweb( + E.base(), + E.v1(), + E.v3(), + ) + ) + + self.browse(self.v2).write({'application': 'enabled'}) + arch = self.read_combined(self.v0)['arch'] + self.assertEqual( + ET.fromstring(arch), + E.qweb( + E.base(), + E.v1(), + E.v2(), + E.v3(), + ) + ) + + def test_mandatory_no_disabled(self): + with self.assertRaises(Exception): + self.browse(self.v1).write({'application': 'disabled'}) + class TestXPathExtentions(common.BaseCase): def test_hasclass(self): tree = E.node(