From 6f0660eaa075fe46b921583bd8e253d6bfd40058 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 6 Dec 2010 14:18:18 +0100 Subject: [PATCH] [FIX] orm.read_group: support ordering by any field (not just m2o ones) bzr revid: odo@openerp.com-20101206131818-ibah9gt409jbil3l --- bin/osv/orm.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 4a54267053c..b66aa390e57 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2299,19 +2299,14 @@ class orm(orm_template): if val == None: r[fld] = False alldata[r['id']] = r del r['id'] - if groupby and fget[groupby]['type'] == 'many2one': - data_ids = self.search(cr, uid, [('id', 'in', alldata.keys())], order=orderby or groupby, context=context) - # the IDS of the records that has groupby field value = False or '' - # should be added too - data_ids += filter(lambda x:x not in data_ids, alldata.keys()) - data = self.read(cr, uid, data_ids, groupby and [groupby] or ['id'], context=context) - # 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.sort(lambda x,y: cmp(data_ids.index(x['id']), data_ids.index(y['id']))) - else: - #FIXME: handle orderby param for non-m2o too! - data = self.read(cr, uid, alldata.keys(), groupby and [groupby] or ['id'], context=context) - if groupby: - data.sort(lambda x,y:cmp(x[groupby],y[groupby])) + + data_ids = self.search(cr, uid, [('id', 'in', alldata.keys())], order=orderby or groupby, context=context) + # the IDS of records that have groupby field value = False or '' should be sorted too + data_ids += filter(lambda x:x not in data_ids, alldata.keys()) + data = self.read(cr, uid, data_ids, groupby and [groupby] or ['id'], context=context) + # 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.sort(lambda x,y: cmp(data_ids.index(x['id']), data_ids.index(y['id']))) + for d in data: if groupby: d['__domain'] = [(groupby, '=', alldata[d['id']][groupby] or False)] + domain