[IMP]:avg/sum for group by
bzr revid: nch@tinyerp.com-20100308095018-jc61r4jy2y4rug5m
This commit is contained in:
+11
-9
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -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)
|
||||
@@ -320,8 +322,8 @@ class many2one(_column):
|
||||
except except_orm:
|
||||
record_name = {}
|
||||
record_name[record] = '// Access Denied //'
|
||||
names.update(record_name)
|
||||
|
||||
names.update(record_name)
|
||||
|
||||
for r in res.keys():
|
||||
if res[r] and res[r] in names:
|
||||
res[r] = (res[r], names[res[r]])
|
||||
@@ -629,7 +631,7 @@ class function(_column):
|
||||
self._multi = multi
|
||||
if 'relation' in args:
|
||||
self._obj = args['relation']
|
||||
|
||||
|
||||
self.digits = args.get('digits', (16,2))
|
||||
self.digits_compute = args.get('digits_compute', None)
|
||||
|
||||
@@ -642,7 +644,7 @@ class function(_column):
|
||||
|
||||
if not fnct_search and not store:
|
||||
self.selectable = False
|
||||
|
||||
|
||||
if store:
|
||||
self._classic_read = True
|
||||
self._classic_write = True
|
||||
@@ -681,14 +683,14 @@ class function(_column):
|
||||
if self._type == "many2one" :
|
||||
# Filtering only integer/long values if passed
|
||||
res_ids = [x for x in res.values() if x and isinstance(x, (int,long))]
|
||||
|
||||
|
||||
if res_ids:
|
||||
obj_model = obj.pool.get(self._obj)
|
||||
dict_names = dict(obj_model.name_get(cr, user, res_ids, context))
|
||||
for r in res.keys():
|
||||
if res[r] and res[r] in dict_names:
|
||||
res[r] = (res[r], dict_names[res[r]])
|
||||
|
||||
|
||||
if self._type == 'binary' and context.get('bin_size', False):
|
||||
# convert the data returned by the function with the size of that data...
|
||||
res = dict(map( get_nice_size, res.items()))
|
||||
@@ -838,7 +840,7 @@ class dummy(function):
|
||||
|
||||
def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
|
||||
return {}
|
||||
|
||||
|
||||
def __init__(self, *arg, **args):
|
||||
self.arg = arg
|
||||
self._relations = []
|
||||
|
||||
+3
-6
@@ -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)
|
||||
@@ -1871,13 +1871,10 @@ class orm(orm_template):
|
||||
fields_pre = [f for f in float_int_fields if
|
||||
f == self.CONCURRENCY_CHECK_FIELD
|
||||
or (f in self._columns and getattr(self._columns[f], '_classic_write'))]
|
||||
avg_fields = context.get('avg',[])
|
||||
for f in fields_pre:
|
||||
if f not in ['id','sequence']:
|
||||
if f in avg_fields:
|
||||
flist += ',avg('+f+') as '+f
|
||||
else:
|
||||
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 = {}
|
||||
|
||||
Reference in New Issue
Block a user