diff --git a/odoo/models.py b/odoo/models.py index 84e4b16b399..fba69554872 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6056,7 +6056,9 @@ Fields: # diff(), therefore evaluating line._prefetch_ids with an empty # cache simply returns nothing, which discards the prefetching # optimization! - record[name] + record._cache[name] = tuple( + line_snapshot[''].id for line_snapshot in self[name] + ) for line_snapshot in self[name]: line = line_snapshot[''] line = line._origin or line @@ -6080,11 +6082,13 @@ Fields: nametree = PrefixTree(self.browse(), field_onchange) if first_call: - values.update(self.default_get([ - name - for name in nametree - if name not in values - ])) + names = [name for name in values if name != 'id'] + missing_names = [name for name in nametree if name not in values] + defaults = self.default_get(missing_names) + for name in missing_names: + values[name] = defaults.get(name, False) + if name in defaults: + names.append(name) # prefetch x2many lines: this speeds up the initial snapshot by avoiding # to compute fields on new records as much as possible, as that can be