summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/services/data_manager.js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-09-04 15:34:55 +0200
committerMartin Geubelle <mge@odoo.com>2017-09-06 16:34:18 +0200
commitbae4aacad8aa59b1950092b3f79dc8c7233c9c42 (patch)
treeef0ae60337313a32cf4600d9b32588443ed1f713 /addons/web/static/src/js/services/data_manager.js
parent3052a434947f71955a5e287e373164be46f8860c (diff)
[FIX] web: edit x2many editable list view after resequence
In an embedded editable list view with the widget `handle`, resequencing a record and try to edit it afterwards won't work. The selected record isn't the correct one, as if the resequencing had no impact. To make this work, the list datapoint needs to be ordered by the field with the widget `handle` ; if it isn't, resequencing the records won't change the x2many data order but the list view expects the same order.
Diffstat (limited to 'addons/web/static/src/js/services/data_manager.js')
-rw-r--r--addons/web/static/src/js/services/data_manager.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/addons/web/static/src/js/services/data_manager.js b/addons/web/static/src/js/services/data_manager.js
index 105d7f30d69..4bf1748fbab 100644
--- a/addons/web/static/src/js/services/data_manager.js
+++ b/addons/web/static/src/js/services/data_manager.js
@@ -336,20 +336,30 @@ return core.Class.extend({
attrs.mode = mode;
if (mode in attrs.views) {
var view = attrs.views[mode];
- // process the default_order, which is like 'name,id desc'
- // but we need it like [{name: 'name', asc: true}, {name: 'id', asc: false}]
var defaultOrder = view.arch.attrs.default_order;
if (defaultOrder) {
+ // process the default_order, which is like 'name,id desc'
+ // but we need it like [{name: 'name', asc: true}, {name: 'id', asc: false}]
attrs.orderedBy = _.map(defaultOrder.split(','), function (order) {
order = order.trim().split(' ');
return {name: order[0], asc: order[1] !== 'desc'};
});
+ } else {
+ // if there is a field with widget `handle`, the x2many
+ // needs to be ordered by this field to correctly display
+ // the records
+ var handleField = _.find(view.arch.children, function (child) {
+ return child.attrs && child.attrs.widget === 'handle';
+ });
+ if (handleField) {
+ attrs.orderedBy = [{name: handleField.attrs.name, asc: true}];
+ }
}
// detect editables list has they behave differently with respect
// to the sorting (changes are not sorted directly)
if (mode === 'list' && view.arch.attrs.editable) {
attrs.keepChangesUnsorted = true;
- }
+ }
}
}
if (attrs.Widget.prototype.fieldsToFetch) {