[FIX] fields: make convert_to_cache() more robust with inverse one2many
authorRaphael Collet <rco@openerp.com>
Wed, 17 Sep 2014 12:16:25 +0000 (14:16 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 17 Sep 2014 14:01:02 +0000 (16:01 +0200)
When a one2many field uses an integer field as inverse, the onchange method on
the second model may receive a dictionary for the value of the integer field.
This is because the client expects that field to be a many2one.

openerp/fields.py

index 0104302..e103ee1 100644 (file)
@@ -903,6 +903,9 @@ class Integer(Field):
     type = 'integer'
 
     def convert_to_cache(self, value, record, validate=True):
+        if isinstance(value, dict):
+            # special case, when an integer field is used as inverse for a one2many
+            return value.get('id', False)
         return int(value or 0)
 
     def convert_to_read(self, value, use_name_get=True):