Skip to content

Commit

Permalink
[FIX] models: in onchange, false changes where detected in many2many …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
rco-odoo committed Feb 21, 2015
1 parent d350f5b commit 121b8e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions openerp/addons/test_new_api/tests/test_onchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ def test_onchange_one2many(self):
}),
(1, message.id, {
'name': "[%s] %s" % ("Foo", USER.name),
# Note: size is computed because it was not provided beforehand
'size': len(BODY),
}),
])

Expand Down
5 changes: 5 additions & 0 deletions openerp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5787,6 +5787,11 @@ def onchange(self, values, field_name, field_onchange):
# 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()
Expand Down

0 comments on commit 121b8e6

Please sign in to comment.