summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornch@tinyerp.com <>2010-03-08 15:20:18 +0530
committernch@tinyerp.com <>2010-03-08 15:20:18 +0530
commitdf13708d1368ea4ed3b9373e8cc89acefbf4fa2c (patch)
tree780d4a7a64995e659f3fa8917fed4e078b7716f9
parent546b76d5d3ed95af3f8d7d38504f25732baac4da (diff)
parent8856a549f738f983795d29da330044568147828a (diff)
[IMP]:avg/sum for group by
bzr revid: nch@tinyerp.com-20100308095018-jc61r4jy2y4rug5m
-rw-r--r--bin/osv/fields.py20
-rw-r--r--bin/osv/orm.py9
2 files changed, 14 insertions, 15 deletions
diff --git a/bin/osv/fields.py b/bin/osv/fields.py
index 5d373a168ea..ce02de20a27 100644
--- a/bin/osv/fields.py
+++ b/bin/osv/fields.py
@@ -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 = []
diff --git a/bin/osv/orm.py b/bin/osv/orm.py
index 0165d4e7a4a..7f412be0a7a 100644
--- a/bin/osv/orm.py
+++ b/bin/osv/orm.py
@@ -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 = {}