[IMP]:Avg/sum for groupby

bzr revid: nch@tinyerp.com-20100308094036-hpvzsvlygup7s0e7
This commit is contained in:
nch@tinyerp.com 2010-03-08 15:10:36 +05:30
parent 325bcd1c5b
commit 8856a549f7
2 changed files with 14 additions and 11 deletions

View File

@ -80,6 +80,7 @@ class _column(object):
self.view_load = 0
self.select = select
self.selectable = True
self.group_operator = args.get('group_operator', False)
for a in args:
if args[a]:
setattr(self, a, args[a])
@ -177,6 +178,7 @@ class float(_column):
self.digits = digits
self.digits_compute = digits_compute
def digits_change(self, cr):
if self.digits_compute:
t = self.digits_compute(cr)

View File

@ -1007,7 +1007,7 @@ class orm_template(object):
if fields and f not in fields:
continue
res[f] = {'type': self._columns[f]._type}
for arg in ('string', 'readonly', 'states', 'size', 'required',
for arg in ('string', 'readonly', 'states', 'size', 'required', 'group_operator',
'change_default', 'translate', 'help', 'select', 'selectable'):
if getattr(self._columns[f], arg):
res[f][arg] = getattr(self._columns[f], arg)
@ -1873,7 +1873,8 @@ class orm(orm_template):
or (f in self._columns and getattr(self._columns[f], '_classic_write'))]
for f in fields_pre:
if f not in ['id','sequence']:
flist += ',sum('+f+') as '+f
operator = fget[f].get('group_operator','sum')
flist += ','+operator+'('+f+') as '+f
cr.execute('select min(%s.id) as id,' % self._table + flist + ' from ' + ','.join(tables) + where_clause + ' group by '+ groupby + limit_str + offset_str, where_params)
alldata = {}