[FIX] models: in method onchange(), check for record dirtiness only on *2many fiels
authorRaphael Collet <rco@openerp.com>
Wed, 10 Sep 2014 10:10:22 +0000 (12:10 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 10 Sep 2014 12:26:12 +0000 (14:26 +0200)
Cascading onchanges can be caused by a related field computed in cache.  This
causes a bug in sale order lines, were setting the uom field forces reading
product fields, which are inherited from product templates.  The inherited
fields are computed as related fields, which marks the product record as dirty.
This subsequently triggers an onchange on the product field, which resets the
uom field!

openerp/models.py

index 79a61a7..b531678 100644 (file)
@@ -5694,8 +5694,9 @@ class BaseModel(object):
                 # determine which fields have been modified
                 for name, oldval in values.iteritems():
                     newval = record[name]
-                    if newval != oldval or getattr(newval, '_dirty', False):
-                        field = self._fields[name]
+                    field = self._fields[name]
+                    if newval != oldval or \
+                            field.type in ('one2many', 'many2many') and newval._dirty:
                         result['value'][name] = field.convert_to_write(
                             newval, record._origin, subfields.get(name),
                         )