From 5cf8220362f2086ea7845eefb7805b8a7b0b8862 Mon Sep 17 00:00:00 2001 From: nans Date: Fri, 30 Apr 2021 17:14:18 +0200 Subject: [PATCH] [FIX] onchange_helper: compute related values for onchange applications --- onchange_helper/models/base.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/onchange_helper/models/base.py b/onchange_helper/models/base.py index 4cc24ca2b..8a036525e 100644 --- a/onchange_helper/models/base.py +++ b/onchange_helper/models/base.py @@ -51,15 +51,18 @@ class Base(models.AbstractModel): else: # We get default values, they may be used in onchange record_values = self.default_get(self._fields.keys()) - for field in self._fields: - if field not in all_values: - all_values[field] = record_values.get(field, False) + + for fn, field in self._fields.items(): + if not field.related and fn not in all_values: # related fields are False + all_values[fn] = record_values.get(fn, False) new_values = {} - for field in onchange_fields: - onchange_values = self.onchange(all_values, field, onchange_specs) - new_values.update(self._get_new_values(values, onchange_values)) - all_values.update(new_values) + with self.env.do_in_onchange(): # avoid cache issues with related fields! + new = self.new(all_values) + for field in onchange_fields: + onchange_values = new.onchange(all_values, field, onchange_specs) + new_values.update(self._get_new_values(values, onchange_values)) + all_values.update(new_values) return { f: v