[FIX] core: do not force recomputation of fields on new records

The method `recompute()` should not recompute fields on new records.
This is both a speedup (those recomputations are not necessary), and
fixes an error following an `onchange()` (a field recomputed in an
environment with the wrong context.)

OPW 2184998

closes odoo/odoo#47545

X-original-commit: fa852ba1c5707b71469c410063f338eef261ab2b
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
Raphael Collet
2020-03-12 17:46:06 +00:00
parent b53614fcc5
commit 5771772b61
2 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -5849,6 +5849,9 @@ Record ids: %(records)s
if not recs:
return
if field.compute and field.store:
# do not force recomputation on new records; those will be
# recomputed by accessing the field on the records
recs = recs.filtered('id')
try:
recs.mapped(field.name)
except MissingError:
@@ -5865,9 +5868,8 @@ Record ids: %(records)s
if fnames is None:
# recompute everything
fields_to_compute = self.env.fields_to_compute()
while fields_to_compute:
process(next(iter(fields_to_compute)))
for field in list(self.env.fields_to_compute()):
process(field)
else:
fields = [self._fields[fname] for fname in fnames]
+2 -2
View File
@@ -1813,7 +1813,7 @@ class Form(object):
)
self._changed.clear()
self._model.flush()
self._model.invalidate_cache()
self._model.env.clear() # discard cache and pending recomputations
return r
def _values_to_save(self, all_fields=False):
@@ -1901,7 +1901,7 @@ class Form(object):
record = self._model.browse(self._values.get('id'))
result = record.onchange(self._onchange_values(), fields, spec)
self._model.flush()
self._model.invalidate_cache()
self._model.env.clear() # discard cache and pending recomputations
if result.get('warning'):
_logger.getChild('onchange').warning("%(title)s %(message)s" % result.get('warning'))
values = result.get('value', {})