[FIX] models: in onchange, false changes where detected in many2many fields
This was due to secondary fields loaded from database in 'onchange' mode. In that mode, the secondary fields were marked 'dirty', and therefore returned by the method `onchange`. The fix consists in loading those secondary fields in cache before processing the onchanges. This incidentally fixes a test on method `onchange`: in a one2many field, some dirty fields were unexpectedly returned in the result. This was due to those fields being loaded while processing onchanges.
This commit is contained in:
parent
d350f5b59e
commit
121b8e6800
|
@ -146,8 +146,6 @@ class TestOnChange(common.TransactionCase):
|
||||||
}),
|
}),
|
||||||
(1, message.id, {
|
(1, message.id, {
|
||||||
'name': "[%s] %s" % ("Foo", USER.name),
|
'name': "[%s] %s" % ("Foo", USER.name),
|
||||||
# Note: size is computed because it was not provided beforehand
|
|
||||||
'size': len(BODY),
|
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -5787,6 +5787,11 @@ class BaseModel(object):
|
||||||
# attach `self` with a different context (for cache consistency)
|
# attach `self` with a different context (for cache consistency)
|
||||||
record._origin = self.with_context(__onchange=True)
|
record._origin = self.with_context(__onchange=True)
|
||||||
|
|
||||||
|
# load fields on secondary records, to avoid false changes
|
||||||
|
with env.do_in_onchange():
|
||||||
|
for field_seq in secondary:
|
||||||
|
record.mapped(field_seq)
|
||||||
|
|
||||||
# determine which field(s) should be triggered an onchange
|
# determine which field(s) should be triggered an onchange
|
||||||
todo = list(names) or list(values)
|
todo = list(names) or list(values)
|
||||||
done = set()
|
done = set()
|
||||||
|
|
Loading…
Reference in New Issue