summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-11-30 10:48:29 +0000
committerRaphael Collet <rco@odoo.com>2020-11-30 16:50:02 +0000
commit80c1dad6d9124da9459ce38d9e8c03e5c461c180 (patch)
treecad059c57885e6f4e82f00a5b65bc762d6c015b3 /odoo
parentf5de98a2ad67f6e507f81cff34ddf4f0dcae816a (diff)
[FIX] core: avoid multiple calls to default_get() in onchange
Upon the first call to `onchange`, the `values` dict is filled with default values. But the fields without a default are left unassigned. This allows to compute fields when accessing them, but non-computed fields will ask again for their default value, which is a waste of time because we know they don't have one. This may even be a performance issue on forms with many fields. Fix this issue by completing `values` with falsy values, and consider the fields with some initial value (given or default) as the assigned ones for triggering onchanges. This explicitly triggers the computation of fields that depend on fields with some initial value, without forcing them to `False`. Also avoid accessing x2many fields on the record in `snapshot.diff()`. Enable the prefetching by simply putting the right value in cache. closes odoo/odoo#62627 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/models.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/odoo/models.py b/odoo/models.py
index 1102cd93f7f..5c94aa0acca 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -6053,7 +6053,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['<record>'].id for line_snapshot in self[name]
+ )
for line_snapshot in self[name]:
line = line_snapshot['<record>']
line = line._origin or line
@@ -6077,11 +6079,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