[IMP] replace check_mode python-level constraint by an SQL CHECK constraint
This commit is contained in:
parent
9555b32c7b
commit
0f5424eac4
|
@ -206,16 +206,14 @@ class view(osv.osv):
|
|||
return False
|
||||
return True
|
||||
|
||||
def _check_mode(self, cr, uid, ids, context=None):
|
||||
for v in self.read(cr, uid, ids, ['inherit_id', 'mode'], context=context):
|
||||
if v['mode'] == 'extension' and not v['inherit_id']:
|
||||
raise Exception(
|
||||
_("A view extending nothing can not be an extension view"))
|
||||
return True
|
||||
|
||||
_sql_constraints = [
|
||||
('inheritance_mode',
|
||||
"CHECK (mode != 'extension' OR inherit_id IS NOT NULL)",
|
||||
"Invalid inheritance mode: if the mode is 'extension', the view must"
|
||||
" extend an other view"),
|
||||
]
|
||||
_constraints = [
|
||||
(_check_xml, 'Invalid view definition', ['arch']),
|
||||
(_check_mode, "Invalid mode for inheritance", ['mode', 'inherit_id']),
|
||||
]
|
||||
|
||||
def _auto_init(self, cr, context=None):
|
||||
|
|
|
@ -7,7 +7,10 @@ import unittest2
|
|||
from lxml import etree as ET
|
||||
from lxml.builder import E
|
||||
|
||||
from psycopg2 import IntegrityError
|
||||
|
||||
from openerp.tests import common
|
||||
import openerp.tools
|
||||
|
||||
Field = E.field
|
||||
|
||||
|
@ -829,6 +832,7 @@ class ViewModeField(ViewCase):
|
|||
}))
|
||||
self.assertEqual(view2.mode, 'extension')
|
||||
|
||||
@openerp.tools.mute_logger('openerp.sql_db')
|
||||
def testModeExplicit(self):
|
||||
view = self.browse(self.create({
|
||||
'inherit_id': None,
|
||||
|
@ -841,13 +845,14 @@ class ViewModeField(ViewCase):
|
|||
}))
|
||||
self.assertEqual(view.mode, 'primary')
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
with self.assertRaises(IntegrityError):
|
||||
self.create({
|
||||
'inherit_id': None,
|
||||
'mode': 'extension',
|
||||
'arch': '<qweb/>'
|
||||
})
|
||||
|
||||
@openerp.tools.mute_logger('openerp.sql_db')
|
||||
def testPurePrimaryToExtension(self):
|
||||
"""
|
||||
A primary view with inherit_id=None can't be converted to extension
|
||||
|
@ -856,7 +861,7 @@ class ViewModeField(ViewCase):
|
|||
'inherit_id': None,
|
||||
'arch': '<qweb/>'
|
||||
}))
|
||||
with self.assertRaises(Exception):
|
||||
with self.assertRaises(IntegrityError):
|
||||
view_pure_primary.write({'mode': 'extension'})
|
||||
|
||||
def testInheritPrimaryToExtension(self):
|
||||
|
|
Loading…
Reference in New Issue