From 5279a08a005bacee4ecd76cc189d8ce65c8e600c Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Fri, 20 Nov 2020 08:00:31 +0000 Subject: [FIX] core: invalidation of computed editable field in one2many This fixes the issue introduced by revision fd50ba9fb838067fab0b920470cf79b9c94d785c The way computed fields are invalidated depends on the order of the dict passed as a parameter to method onchange(). This causes some unexpected behavior when dealing with computed editable fields: the user loses the value in that field because of the onchange. Explanation: during the onchange, the modified field is cached by record._update_cache(changed_values, validate=True) If the field is a one2many, 'value' contains an update command for each modified line. Because of 'validate=True', the assignment triggers field computations on the lines, which are already handled by another call to onchange(). In case anything on the parent model modifies some line, the whole one2many values are returned to the user, and accidentally recomputed fields show up in the interface. closes odoo/odoo#62060 Signed-off-by: Raphael Collet (rco) --- odoo/fields.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'odoo/fields.py') diff --git a/odoo/fields.py b/odoo/fields.py index 603e2a90a3e..8ddc0c1b422 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -956,7 +956,8 @@ class Field(MetaField('DummyField', (object,), {})): # not stored and not computed -> default # # on a new record w/ origin: - # stored -> fetch from origin (computation done above) + # stored and not (computed and readonly) -> fetch from origin + # stored and computed and readonly -> compute # not stored and computed -> compute # not stored and not computed -> default # @@ -982,7 +983,7 @@ class Field(MetaField('DummyField', (object,), {})): ])) value = env.cache.get(record, self) - elif self.store and record._origin: + elif self.store and record._origin and not (self.compute and self.readonly): # new record with origin: fetch from origin value = self.convert_to_cache(record._origin[self.name], record) env.cache.set(record, self, value) -- cgit v1.2.3