[IMP] prevent changing a view from application: always to application: disabled

not sure that's actually useful, and can still go always -> enabled -> disabled...
This commit is contained in:
Xavier Morel 2014-05-27 11:52:57 +02:00
parent d82ffb8728
commit e2f41d09ba
2 changed files with 52 additions and 0 deletions

View File

@ -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,

View File

@ -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(