Merge lp:~openerp-dev/openerp-web/6.1-opw-581785-cbi into lp:openerp-web/6.1

Proposed by Chris Biersbach (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openerp-web/6.1-opw-581785-cbi
Merge into: lp:openerp-web/6.1
Diff against target: 15 lines (+5/-0)
1 file modified
addons/web/static/src/js/data.js (+5/-0)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/6.1-opw-581785-cbi
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+134066@code.launchpad.net

Description of the change

The bug that was encountered: When sorting by product on pricelist versions, you get a wrong order.

The reason: The web client does this by comapring using < and >. If the field is a many2one (as in this case), its value is an array [id, name]. Thus, using < and > on arrays does a comapre on the first element first. The products are does sorted by id, and not by name.

The fix: This introduces a check to see whether the field is a many2one field. In that case, I explicitly do a compare of the 2nd element in the array to correctly sort by name.

To post a comment you must log in.

Unmerged revisions

2480. By Chris Biersbach (OpenERP)

[FIX] When sorting by a many2one field in list view, the id was taken as sorting criterium. THis now detects many2one fields and instead uses the name to get behavior consistent with what the user expects.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/data.js'
2--- addons/web/static/src/js/data.js 2012-09-06 12:48:16 +0000
3+++ addons/web/static/src/js/data.js 2012-11-13 10:18:21 +0000
4@@ -756,6 +756,11 @@
5 sign = -1;
6 field = field.slice(1);
7 }
8+ // very thorough test to check whether this is a o2m field
9+ check_m2o = function(f) {
10+ return f[field] instanceof Array && f[field].length == 2 && typeof(f[field][0]) == 'number' && typeof(f[field][1]) == 'string';
11+ }
12+ if (check_m2o(a) && check_m2o(b)) return sign * compare(a[field][1], b[field][1])
13 return sign * compare(a[field], b[field]);
14 }, 0);
15 });