From f72e2a47b70fc3aef30ffcad4db2918c15ba5356 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 28 Jan 2010 11:21:23 +0530 Subject: [PATCH] [IMP]:group by on date/datetime field will result in Today,Yesterday or Old categories bzr revid: nch@tinyerp.com-20100128055123-6fvuupq0l5uyyujp --- bin/osv/orm.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 97f83cdf577..da8ecea3d9f 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1832,11 +1832,23 @@ class orm(orm_template): alldata[r['id']] = r del r['id'] + today = '' + if fget.has_key(groupby) and fget[groupby]['type'] in ('date','datetime'): + today = datetime.date.today() + yesterday = (today - datetime.timedelta(days=1)).strftime('%Y-%m-%d') + data = self.read(cr, uid, alldata.keys(), [groupby], context=context) for d in data: if fget.has_key(groupby): if fget[groupby]['type'] == 'many2one': d[groupby] = d[groupby] and d[groupby][1] or '' + if today: + if d[groupby] == str(today): + d[groupby] = 'Today' + elif d[groupby] == yesterday: + d[groupby] = 'Yesterday' + else: + d[groupby] = 'Old' d['__domain'] = [(groupby,'=',alldata[d['id']][groupby] or False)] + domain del alldata[d['id']][groupby] d.update(alldata[d['id']]) @@ -2424,7 +2436,7 @@ class orm(orm_template): def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'): if not context: context = {} - #ids = map(lambda x:int(x), ids) + #ids = map(lambda x:int(x), ids) if not ids: return [] if fields_to_read == None: