diff options
Diffstat (limited to 'odoo/models.py')
| -rw-r--r-- | odoo/models.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/odoo/models.py b/odoo/models.py index d82806b6862..f3a2b4d7530 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -5857,6 +5857,10 @@ Fields: names (in view order), or False :param field_onchange: dictionary mapping field names to their on_change attribute + + When ``field_name`` is falsy, the method first adds default values + to ``values``, applies onchange methods to them, and return all the + fields in ``field_onchange``. """ # this is for tests using `Form` self.flush() @@ -5869,6 +5873,8 @@ Fields: else: names = [] + first_call = not names + if not all(name in self._fields for name in names): return {} @@ -5931,14 +5937,16 @@ Fields: ) ) - def diff(self, other): + def diff(self, other, force=False): """ Return the values in ``self`` that differ from ``other``. Requires record cache invalidation for correct output! """ record = self['<record>'] result = {} for name, subnames in self['<tree>'].items(): - if (name == 'id') or (other.get(name) == self[name]): + if name == 'id': + continue + if not force and other.get(name) == self[name]: continue field = record._fields[name] if field.type not in ('one2many', 'many2many'): @@ -5968,6 +5976,16 @@ Fields: nametree = PrefixTree(self.browse(), field_onchange) + if first_call: + names = list(nametree) + values.update(self.default_get([ + name + for name in names + if name not in values + ])) + for name in names: + values.setdefault(name, False) + # prefetch x2many lines without data (for the initial snapshot) for name, subnames in nametree.items(): if subnames and values.get(name): @@ -6065,7 +6083,7 @@ Fields: # determine values that have changed by comparing snapshots self.invalidate_cache() - result['value'] = snapshot1.diff(snapshot0) + result['value'] = snapshot1.diff(snapshot0, force=first_call) # format warnings warnings = result.pop('warnings') |
