[FIX] orm: set default before removing magic fields
authordhr-odoo <dhr@tinyerp.com>
Wed, 9 Jul 2014 07:23:36 +0000 (12:53 +0530)
committerMartin Trigaux <mat@openerp.com>
Fri, 1 Aug 2014 13:37:01 +0000 (15:37 +0200)
When a record is created, the magic fields (id, create_date,...) are first removed from the vals as the user should not set a value for these.
However if a value for this is given in default value (e.g. defined in an ir.value), the creation would crash (sql error : column specified more than once) as the magic column would be added again.

openerp/osv/orm.py

index 0a38ccf..f0c8337 100644 (file)
@@ -4394,6 +4394,8 @@ class BaseModel(object):
             self._transient_vacuum(cr, user)
 
         self.check_access_rights(cr, user, 'create')
+        
+        vals = self._add_missing_default_values(cr, user, vals, context)
 
         if self._log_access:
             for f in LOG_ACCESS_COLUMNS:
@@ -4401,7 +4403,6 @@ class BaseModel(object):
                     _logger.warning(
                         'Field `%s` is not allowed when creating the model `%s`.',
                         f, self._name)
-        vals = self._add_missing_default_values(cr, user, vals, context)
 
         tocreate = {}
         for v in self._inherits: