From 9b3131cae1cff2cd5b8e32e62dc6895abdd7a222 Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 6 Sep 2007 14:12:23 +0000 Subject: [PATCH] Add integrity on fields that are selections bzr revid: ced-f106c9b085ebef6e5875e115540a30bb9daaf014 --- bin/osv/orm.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 2d70f5cbe2c..c711ae3e6c7 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -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()'