[FIX] unwarranted assumption that name_get(ids) and read(ids) will return the same records in the same order

There is actually no such guarantee, neither name_get nor read
guarantee they'll return records in input order, let alone in the same
order as one another, and both are free to skip records as they see
fit (kinda).

=> convert the name_get result to a dict, and then fill in the
display_name for each record returned by read() using get()

bzr revid: xmo@openerp.com-20121213130548-x1h6czyru5nc6wwm
This commit is contained in:
Xavier Morel 2012-12-13 14:05:48 +01:00
parent d63781bf5c
commit 7acadc00c6
1 changed files with 7 additions and 6 deletions

View File

@ -1059,14 +1059,15 @@ class DataSet(openerpweb.Controller):
def _call_kw(self, req, model, method, args, kwargs):
# Temporary implements future display_name special field for model#read()
if method == 'read' and kwargs.get('context') and kwargs['context'].get('future_display_name'):
if method == 'read' and kwargs.get('context', {}).get('future_display_name'):
if 'display_name' in args[1]:
names = req.session.model(model).name_get(args[0], **kwargs)
names = dict(req.session.model(model).name_get(args[0], **kwargs))
args[1].remove('display_name')
r = getattr(req.session.model(model), method)(*args, **kwargs)
for i in range(len(r)):
r[i]['display_name'] = names[i][1] or "%s#%d" % (model, names[i][0])
return r
records = req.session.model(model).read(*args, **kwargs)
for record in records:
record['display_name'] = \
names.get(record['id']) or "%s#%d" % (model, (record['id']))
return records
return getattr(req.session.model(model), method)(*args, **kwargs)