summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorlen-odoo <len@odoo.com>2018-05-11 16:59:10 +0200
committerlen-odoo <35492570+len-odoo@users.noreply.github.com>2018-05-16 08:04:53 +0200
commit25548eb7e963632668438f939401403431201904 (patch)
tree181b16062ce997baa7217d537c4f272b15f9c82d /addons/web/static/src/js/views/basic/basic_model.js
parent5a943390f2abf82883316052ad0eeb601b0194c3 (diff)
[FIX] web: sort relational fields by their names
When sorting records according to a many2one field in a list view embedded in a form view, the js would sort according to their ids, in a seemingly arbitrary order. Thus sorting records according to a field with values in ("a", "b", "c") could be sorted as "a", "a", "c", "b" instead of "a", "a", "b", "c". We make the comparison on the name of the field instead. opw 1838860
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 9e8afe1629f..d0eed4dc524 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -4100,10 +4100,20 @@ var BasicModel = AbstractModel.extend({
var r2 = self.localData[record2ID];
var data1 = _.extend({}, r1.data, r1._changes);
var data2 = _.extend({}, r2.data, r2._changes);
- if (data1[order.name] < data2[order.name]) {
+
+ // Default value to sort against: the value of the field
+ var orderData1 = data1[order.name];
+ var orderData2 = data2[order.name];
+
+ // If the field is a relation, sort on the display_name of those records
+ if (list.fields[order.name].type === 'many2one') {
+ orderData1 = orderData1 ? self.localData[orderData1].data.display_name : "";
+ orderData2 = orderData2 ? self.localData[orderData2].data.display_name : "";
+ }
+ if (orderData1 < orderData2) {
return order.asc ? -1 : 1;
}
- if (data1[order.name] > data2[order.name]) {
+ if (orderData1 > orderData2) {
return order.asc ? 1 : -1;
}
return compareRecords(record1ID, record2ID, level + 1);