[IMP] search_read code

bzr revid: xmo@openerp.com-20130821135853-i9g6cvi52onrmmte
This commit is contained in:
Xavier Morel 2013-08-21 15:58:53 +02:00
parent 4d1b266819
commit 5684c5d286
1 changed files with 7 additions and 8 deletions

View File

@ -4886,17 +4886,16 @@ class BaseModel(object):
:rtype: List of dictionaries. :rtype: List of dictionaries.
""" """
record_ids = self.search(cr, uid, domain or [], offset, limit or False, order or False, context or {}) record_ids = self.search(cr, uid, domain or [], offset=offset, limit=limit, order=order, context=context)
if not record_ids: if not record_ids:
return [] return []
result = self.read(cr, uid, record_ids, fields or [], context or {}) result = self.read(cr, uid, record_ids, fields=fields, context=context)
if len(result) <= 1:
return result
# reorder read # reorder read
if len(result) >= 1: index = dict((r['id'], r) for r in result)
index = {} return [index[x] for x in record_ids if x in index]
for r in result:
index[r['id']] = r
result = [index[x] for x in record_ids if x in index]
return result
def _register_hook(self, cr): def _register_hook(self, cr):
""" stuff to do right after the registry is built """ """ stuff to do right after the registry is built """