[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:
Raphael Collet 2015-02-19 15:09:49 +01:00
parent d350f5b59e
commit 121b8e6800
2 changed files with 5 additions and 2 deletions

View File

@ -146,8 +146,6 @@ class TestOnChange(common.TransactionCase):
}),
(1, message.id, {
'name': "[%s] %s" % ("Foo", USER.name),
# Note: size is computed because it was not provided beforehand
'size': len(BODY),
}),
])

View File

@ -5787,6 +5787,11 @@ class BaseModel(object):
# attach `self` with a different context (for cache consistency)
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
todo = list(names) or list(values)
done = set()