Rifakat (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/6.0-opw-573296-rha into 
lp:openobject-server/6.0.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-573296-rha/+merge/99903

Hello,

read_group() does not aggregate properly for inherited columns.
Added inherited fields in group by with correct table.

One can reproduce it for timesheet line(hr.analytic.timesheet _inherits 
account.analytic.line),
menu "Working Hours" and perform group by.

Please review this fix.

Regards,
Rifakat
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/6.0-opw-573296-rha/+merge/99903
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/6.0-opw-573296-rha.
=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py	2012-03-14 12:49:12 +0000
+++ bin/osv/orm.py	2012-03-29 10:35:30 +0000
@@ -2174,7 +2174,7 @@
         self.pool.get('ir.model.access').check(cr, uid, self._name, 'read', context=context)
         if not fields:
             fields = self._columns.keys()
-
+            
         query = self._where_calc(cr, uid, domain, context=context)
         self._apply_ir_rules(cr, uid, query, 'read', context=context)
 
@@ -2210,19 +2210,20 @@
                 # Don't allow arbitrary values, as this would be a SQL injection vector!
                 raise except_orm(_('Invalid group_by'),
                                  _('Invalid group_by specification: "%s".\nA group_by specification must be a list of valid fields.')%(groupby,))
-
-
-        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'))]
-        for f in fields_pre:
-            if f not in ['id', 'sequence']:
-                group_operator = fget[f].get('group_operator', 'sum')
-                if flist:
-                    flist += ', '
-                qualified_field = '"%s"."%s"' % (self._table, f)
-                flist += "%s(%s) AS %s" % (group_operator, qualified_field, f)
-
+        for f in float_int_fields:
+            if f in ('id', 'sequence'):
+                continue
+            if (f in self._columns and getattr(self._columns[f], '_classic_write')):
+                table = self._table
+            elif (f in self._inherit_fields and getattr(self._inherit_fields[f][2], '_classic_write')):
+                table = self._inherit_fields[f][0].replace('.','_')
+            else:
+                continue
+            group_operator = fget[f].get('group_operator', 'sum')
+            if flist:
+                flist += ', '
+            qualified_field = '"%s"."%s"' % (table, f)
+            flist += "%s(%s) AS %s" % (group_operator, qualified_field, f)
         gb = groupby and (' GROUP BY ' + qualified_groupby_field) or ''
 
         from_clause, where_clause, where_clause_params = query.get_sql()

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to