summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-05-27 11:52:57 +0200
committerXavier Morel <xmo@openerp.com>2014-05-27 11:57:07 +0200
commite2f41d09ba7a5f2e6b0fa8efa1624e257824c992 (patch)
treec614dc42644ae7142698e5332b7c3f555e4f571c
parentd82ffb87289547c8f9013d3f8bebadfe17e16374 (diff)
[IMP] prevent changing a view from application: always to application: disabled
not sure that's actually useful, and can still go always -> enabled -> disabled...
-rw-r--r--openerp/addons/base/ir/ir_ui_view.py8
-rw-r--r--openerp/addons/base/tests/test_views.py44
2 files changed, 52 insertions, 0 deletions
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': '<xpath expr="//base" position="after"><v1/></xpath>',
})
self.v2 = self.create({
'model': 'a',
'inherit_id': self.v0,
'application': 'enabled',
+ 'priority': 9,
'arch': '<xpath expr="//base" position="after"><v2/></xpath>',
})
self.v3 = self.create({
'model': 'a',
'inherit_id': self.v0,
'application': 'disabled',
+ 'priority': 8,
'arch': '<xpath expr="//base" position="after"><v3/></xpath>'
})
@@ -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(