[FIX] ir_values: try to evaluate the given expression before saving it in pickle...
authorMartin Trigaux <mat@openerp.com>
Fri, 9 May 2014 13:04:12 +0000 (15:04 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 9 May 2014 13:04:12 +0000 (15:04 +0200)
The value_unpickled given by xml data is usualy already evaluated but when it is given by the web client, a str is recieved by the method (as the field is a text field). In the later case, we need to evaluate the field before storing to be correctly evaluated as a default value.

bzr revid: mat@openerp.com-20140509130412-ki211x7qdccdnv5w

1  2 
openerp/addons/base/ir/ir_values.py

@@@ -121,7 -122,10 +122,13 @@@ class ir_values(osv.osv)
          record = self.browse(cursor, user, id, context=context)
          if record.key == 'default':
              # default values are pickled on the fly
-             value = pickle.dumps(value)
 -            try:
 -                value = isinstance(value, (str, unicode)) and pickle.dumps(eval(value)) or pickle.dumps(value)
 -            except Exception:
++            if isinstance(value, (str, unicode)):
++                try:
++                    value = pickle.dumps(eval(value))
++                except Exception:
++                    value = pickle.dumps(value)
++            else:
+                 value = pickle.dumps(value)
          self.write(cursor, user, id, {name[:-9]: value}, context=ctx)
  
      def onchange_object_id(self, cr, uid, ids, object_id, context=None):