Skip to content

Commit

Permalink
[FIX] openupgrade_merge_records: filter should be properly applied
Browse files Browse the repository at this point in the history
On many2one/one2many, `mapped` returns a recordset with only non falsy values, so no
need to filter, and we want to do a `write` eventually, not being allowed with the
result of the filter operation.
  • Loading branch information
pedrobaeza committed Mar 27, 2019
1 parent b4214ff commit 94c6852
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions openupgradelib/openupgrade_merge_records.py
Expand Up @@ -363,16 +363,19 @@ def _adjust_merged_values_orm(env, model_name, record_ids, target_record_id,
elif field.type == 'one2many':
op = op or 'merge'
if op == 'merge':
l = filter(lambda x: x is not False, l)
o2m_changes += 1
l.write({field.inverse_name: target_record_id})
elif field.type in ('binary', 'many2one'):
elif field.type == 'binary':
op = op or 'merge'
if op == 'merge':
l = filter(lambda x: x, l)
if not getattr(target_record, field.name) and l and not \
vals.get(field.name):
vals[field.name] = l[:1]
if not getattr(target_record, field.name) and l:
vals[field.name] = l[0]
elif field.type == 'many2one':
op = op or 'merge'
if op == 'merge':
if not getattr(target_record, field.name) and l:
vals[field.name] = l[0]
# Curate values that haven't changed
new_vals = {}
for f in vals:
Expand Down

0 comments on commit 94c6852

Please sign in to comment.