[IMP] orm.read_group: raise if called with group_by being a non-database-stored field
authorOlivier Dony <odo@openerp.com>
Thu, 16 Dec 2010 18:37:08 +0000 (19:37 +0100)
committerOlivier Dony <odo@openerp.com>
Thu, 16 Dec 2010 18:37:08 +0000 (19:37 +0100)
lp bug: https://launchpad.net/bugs/689070 fixed

bzr revid: odo@openerp.com-20101216183708-o61idware1v6tyk3

bin/osv/orm.py

index 895626d..a652ad5 100644 (file)
@@ -2276,7 +2276,10 @@ class orm(orm_template):
                 groupby = groupby[0]
             self._inherits_join_calc(groupby, query)
 
-        assert not groupby or groupby in fields, "Fields in 'groupby' must appear in the list of fields to read (perhaps it's missing in the list view?)"
+        if groupby:
+            assert not groupby or groupby in fields, "Fields in 'groupby' must appear in the list of fields to read (perhaps it's missing in the list view?)"
+            groupby_def = self._columns.get(groupby) or (self._inherit_fields.get(groupby) and self._inherit_fields.get(groupby)[2])
+            assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
 
         fget = self.fields_get(cr, uid, fields)
         float_int_fields = filter(lambda x: fget[x]['type'] in ('float', 'integer'), fields)