Merge lp:~openerp-dev/openobject-server/6.1-opw-584504-rgo into lp:openobject-server/6.1

Proposed by Ravi Gohil (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/6.1-opw-584504-rgo
Merge into: lp:openobject-server/6.1
Diff against target: 31 lines (+10/-2)
1 file modified
openerp/osv/orm.py (+10/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.1-opw-584504-rgo
Reviewer Review Type Date Requested Status
Naresh(OpenERP) Pending
Review via email: mp+145834@code.launchpad.net

Description of the change

Hello,

Scenario to reproduce the issue:
Say for example, I have an object 'res.country.region' object with 'name' and 'code' fields and an m2o field 'region_id' in 'res.country' object and I have a stored functional field 'region_id' in 'res.partner.address' object which takes region from the country assigned to the address(like address.country_id.region_id.id).

Now if I create a new record in 'res.partner.address' object and assign a country to it, respective 'region_id' will be stored in db for 'res_partner_address' table. This works fine.

But, if I have few addresses created with a country assigned to it, and if some user assigns 'region_id' to that country from 'res.country' object itself, you will be able to see that region in 'res.partner.address' object(as the function will calculate the value and show it), but the table 'res_partner_address' will not have value written for that 'region_id'.(To trigger store, one needs to change country and save the record).

This creates problems when someone groups addresses by region, it will show wrong grouping of records.

What this fix will do, it will put the records, which actually don't have value in database, under 'undefined' group.

Thanks.

To post a comment you must log in.

Unmerged revisions

4335. By Ravi Gohil (OpenERP)

[FIX] Incase, stored functional field doesn't have value in database, grouping the records on that field will result in incorrect grouping. (Maintenance Case: 584687)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2012-09-24 14:00:07 +0000
3+++ openerp/osv/orm.py 2013-01-31 13:02:25 +0000
4@@ -2556,9 +2556,12 @@
5 cr.execute('SELECT min(%s.id) AS id, count(%s.id) AS %s_count' % (self._table, self._table, group_count) + (flist and ',') + flist + ' FROM ' + from_clause + where_clause + gb + limit_str + offset_str, where_clause_params)
6 alldata = {}
7 groupby = group_by
8+ undefined = 0
9 for r in cr.dictfetchall():
10 for fld, val in r.items():
11- if val == None: r[fld] = False
12+ if val == None:
13+ undefined = r.get('id')
14+ r[fld] = False
15 alldata[r['id']] = r
16 del r['id']
17
18@@ -2571,7 +2574,12 @@
19 if groupby:
20 data = self.read(cr, uid, data_ids, [groupby], context=context)
21 # restore order of the search as read() uses the default _order (this is only for groups, so the footprint of data should be small):
22- data_dict = dict((d['id'], d[groupby] ) for d in data)
23+ data_dict = {}
24+ for d in data:
25+ if d['id'] == undefined:
26+ data_dict.update({d['id']:False})
27+ else:
28+ data_dict.update({d['id']:d[groupby]})
29 result = [{'id': i, groupby: data_dict[i]} for i in data_ids]
30 else:
31 result = [{'id': i} for i in data_ids]