Add integrity on fields that are selections

bzr revid: ced-f106c9b085ebef6e5875e115540a30bb9daaf014
This commit is contained in:
ced 2007-09-06 14:12:23 +00:00
parent 8db2cf41d7
commit 9b3131cae1
1 changed files with 33 additions and 0 deletions

View File

@ -986,6 +986,23 @@ class orm(object):
upd_todo.append(field)
else:
updend.append(field)
if hasattr(self._columns[field], 'selection') and vals[field]:
if isinstance(self._columns[field], fields.reference):
val = vals[field].split(',')[0]
else:
val = vals[field]
if isinstance(self._columns[field].selection, (tuple, list)):
if val not in dict(self._columns[field].selection):
raise except_orm('ValidateError',
'The value "%s" for the field "%s" is not in the selection' \
% (vals[field], field))
else:
if val not in dict(self._columns[field].selection(
self, cr, user, context=context)):
raise except_orm('ValidateError',
'The value "%s" for the field "%s" is not in the selection' \
% (vals[field], field))
if self._log_access:
upd0.append('write_uid=%d')
upd0.append('write_date=now()')
@ -1099,6 +1116,22 @@ class orm(object):
upd2.append(self._columns[field]._symbol_set[1](vals[field]))
else:
upd_todo.append(field)
if hasattr(self._columns[field], 'selection') and vals[field]:
if isinstance(self._columns[field], fields.reference):
val = vals[field].split(',')[0]
else:
val = vals[field]
if isinstance(self._columns[field].selection, (tuple, list)):
if val not in dict(self._columns[field].selection):
raise except_orm('ValidateError',
'The value "%s" for the field "%s" is not in the selection' \
% (vals[field], field))
else:
if val not in dict(self._columns[field].selection(
self, cr, user, context=context)):
raise except_orm('ValidateError',
'The value "%s" for the field "%s" is not in the selection' \
% (vals[field], field))
if self._log_access:
upd0 += ',create_uid,create_date'
upd1 += ',%d,now()'