From 958c3db076eb33e2ce23be9b58e763dd079d6ac9 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Wed, 3 Aug 2022 07:58:14 +0000 Subject: [PATCH] [FIX] base: make the properties onchange work Purpose ======= Make the onchange work for the properties fields. When changing the container field, we need to update the properties definition. Task-2852259 Part-of: odoo/odoo#95184 --- odoo/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/odoo/models.py b/odoo/models.py index 9ce880f1a8c..2e350a3bf92 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -6768,6 +6768,18 @@ class BaseModel(metaclass=MetaModel): # make a snapshot based on the initial values of record snapshot0 = Snapshot(record, nametree, fetch=(not first_call)) + for name in initial_values: + # TODO: The parent field on "record" can be False, if it was changed, + # (even if if was changed to a not Falsy value) because of + # >>> initial_values = dict(values, **dict.fromkeys(names, False)) + # If it's the case when we will read the properties field on this record, + # it will return False as well (no parent == no definition) but we need + # "snapshot0" to have the old value to be able to compare it with the new one + # and trigger the onchange if necessary. + field = self._fields.get(name) + if field and field.type == 'properties': + snapshot0[name] = initial_values[name] + # store changed values in cache; also trigger recomputations based on # subfields (e.g., line.a has been modified, line.b is computed stored # and depends on line.a, but line.b is not in the form view)