[IMP] handle case where o2m commands are pairs instead of triplets
bzr revid: xmo@openerp.com-20111011081202-y1ou74u038o2kl58
This commit is contained in:
+10
-6
@@ -4785,12 +4785,16 @@ class BaseModel(object):
|
||||
"""
|
||||
o2m_model = self._all_columns[field_name].column._obj
|
||||
|
||||
# extract and handle case of single ids (instead of commands):
|
||||
# convert to LINK_TO commands (4)
|
||||
c1, c2 = itertools.tee(o2m_commands)
|
||||
commands = list(itertools.chain(
|
||||
(command for command in c1 if isinstance(command, (list, tuple))),
|
||||
((4, id, None) for id in c2 if not isinstance(id, (list, tuple)))))
|
||||
# convert single ids and pairs to tripled commands
|
||||
commands = []
|
||||
for o2m_command in o2m_commands:
|
||||
if not isinstance(o2m_command, (list, tuple)):
|
||||
commands.append((4, o2m_command, False))
|
||||
elif len(o2m_command) == 2:
|
||||
command, id = o2m_command
|
||||
commands.append((command, id, False))
|
||||
else:
|
||||
commands.append(o2m_command)
|
||||
|
||||
# extract records to read, by id, in a mapping dict
|
||||
ids_to_read = [id for (command, id, _) in commands if command in (1, 4)]
|
||||
|
||||
@@ -119,3 +119,21 @@ class TestO2MSerialization(unittest2.TestCase):
|
||||
{'name': 'grault'},
|
||||
{'id': ids[5], 'name': 'garply'}
|
||||
])
|
||||
|
||||
def test_LINK_TO_pairs(self):
|
||||
"LINK_TO commands can be written as pairs, instead of triplets"
|
||||
ids = [
|
||||
self.address.create(self.cr, UID, {'name': 'foo'}),
|
||||
self.address.create(self.cr, UID, {'name': 'bar'}),
|
||||
self.address.create(self.cr, UID, {'name': 'baz'})
|
||||
]
|
||||
commands = map(lambda id: (4, id), ids)
|
||||
|
||||
results = list(self.partner.resolve_o2m_commands_to_record_dicts(
|
||||
self.cr, UID, 'address', commands, ['name']))
|
||||
|
||||
self.assertEqual(results, [
|
||||
{'id': ids[0], 'name': 'foo'},
|
||||
{'id': ids[1], 'name': 'bar'},
|
||||
{'id': ids[2], 'name': 'baz'}
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user