diff --git a/bin/osv/orm.py b/bin/osv/orm.py index cc2f554da60..67360050212 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -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: