When an onchange returns a change in a 2many field line (a '1' tuple, update), avoid to return all fields of the *2many field but only the altered field.
Otherwise, the web client regard all the fields of the 2many as dirty, and try to write on all fields (even if the value is the same, thus)
opw-615062
##############################################################################
#
# OpenERP, Open Source Management Solution
-# Copyright (C) 2013 OpenERP (<http://www.openerp.com>).
+# Copyright (C) 2013-2014 OpenERP (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
self.cache = defaultdict(dict) # {field: {id: value, ...}, ...}
self.prefetch = defaultdict(set) # {model_name: set(id), ...}
self.computed = defaultdict(set) # {field: set(id), ...}
- self.dirty = set() # set(record)
+ self.dirty = defaultdict(set) # {record: set(field_name), ...}
self.all = envs
envs.add(self)
return self
if env.in_onchange:
for invf in self.inverse_fields:
invf._update(value, record)
- record._dirty = True
+ record._set_dirty_by(self.name)
# determine more dependent fields, and invalidate them
if self.relational:
# add new and existing records
for record in value:
if not record.id or record._dirty:
- values = dict((k, v) for k, v in record._cache.iteritems() if k in fnames)
+ dirty_fields = record.env.dirty[record]
+ values = dict((k, v) for k, v in record._cache.iteritems() if k in fnames and k in dirty_fields)
values = record._convert_to_write(values)
if not record.id:
result.append((0, 0, values))
def _dirty(self):
""" Return whether any record in `self` is dirty. """
dirty = self.env.dirty
- return any(record in dirty for record in self)
+ return any(bool(dirty.get(record)) for record in self)
- @_dirty.setter
- def _dirty(self, value):
- """ Mark the records in `self` as dirty. """
- if value:
- map(self.env.dirty.add, self)
- else:
- map(self.env.dirty.discard, self)
+ def _set_dirty_by(self, field_name):
+ dirty = self.env.dirty
+ for record in self:
+ dirty[record].add(field_name)
#
# "Dunder" methods