[IMP] orm.read_group: better readability and efficiency in group sorting

bzr revid: odo@openerp.com-20100920090056-xczdsu1o8o8j6015
This commit is contained in:
Olivier Dony 2010-09-20 11:00:56 +02:00
parent baaf9e4490
commit dc05c4b56d
1 changed files with 3 additions and 6 deletions

View File

@ -2268,12 +2268,9 @@ class orm(orm_template):
if groupby and fget[groupby]['type'] == 'many2one':
data_ids = self.search(cr, uid, [('id', 'in', alldata.keys())], order=groupby, context=context)
data_read = self.read(cr, uid, data_ids, groupby and [groupby] or ['id'], context=context)
# restore order of the search as read() uses the default _order:
data = []
for id in data_ids:
for rec in data_read:
if rec['id'] == id:
data.append(rec)
# restore order of the search as read() uses the default _order (this is only for groups, so the size of data_read shoud be small):
data_read.sort(lambda x,y: cmp(data_ids.index(x['id']), data_ids.index(y['id'])))
data = data_read
else:
data = self.read(cr, uid, alldata.keys(), groupby and [groupby] or ['id'], context=context)
if groupby: