[FIX] add constraints in ir.model.fields for selection values.

bzr revid: ysa@tinyerp.com-20110103110333-xb8lm08mejv8nn4i
This commit is contained in:
Yogesh Sakhreliya 2011-01-03 16:33:33 +05:30
parent d4b2226607
commit 4e806c6d30
1 changed files with 20 additions and 0 deletions

View File

@ -185,6 +185,26 @@ class ir_model_fields(osv.osv):
'selectable': lambda *a: 1,
}
_order = "name"
def _check_selection(self, cr, uid, ids, context=None):
obj = self.browse(cr, uid, ids[0], context=context)
try:
temp = eval(obj.selection)
except Exception:
raise except_orm(_('Error'), _("Given key and value in not allowed!"))
if (not isinstance(temp,list)) or (isinstance(temp,list) and not temp):
return False
elif temp:
for tpl in temp:
if not isinstance(tpl,tuple) or (isinstance(tpl,tuple) and len(tpl) != 2):
return False
return True
_constraints = [
(_check_selection, 'Wrong format specified for a field of type selection, it should be [(key,value)]', ['selection'])
]
def _size_gt_zero_msg(self, cr, user, ids, context=None):
return _('Size of the field can never be less than 1 !')