summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorlen-odoo <len@odoo.com>2018-07-24 15:26:41 +0200
committerlen-odoo <35492570+len-odoo@users.noreply.github.com>2018-08-24 17:25:54 +0200
commit818c18e55d0718286ff5bf332186a10f4d7a58ef (patch)
treed983a1fa115cf499b96c169ec4673fde52eafac0 /addons/web/static/src
parenta19d2c98f4c80d162a92d08ce4a43ca6021f3bca (diff)
[FIX] web: fix js data during consecutive sequence of resequence moves
Let x_1, ..., x_a, x_{a+1}, ..., x_{a+k}, x_{a+k+1}, ..., x_{n} be a record sequence ordered by its 'sequence' field. Suppose the reordering occurs between elements x_{a+k} and x_{a+1}. If the subsequence x_1, ..., x_a is ordered, then it does not change. This is also true of the subsequence x_{a+k+1}, ..., x_{n}. The resquence function makes exactly this assumption, and only sends the server the subsequence x_{a+1}, ..., x_{a+k} to update its 'sequence' field. The update of x is done as follows: it is index + offset, where index is the position of x in the subsequence, and offset is the 'sequence' of the first element of the sequence (i.e. x_{a+1}.sequence). It is easy to see that we need another hypothesis: that the sequence numbers are unique. To show it, suppose that the sequence of x_1, ..., x_a is 0, then all x_{a+1}, ..., x_{a+k} have sequence 1, and lastly all x_{a+k}, x_{a+k+1}, ..., x_{n} have sequence 2. Then after the call to the server resequence, the subsequence x_{a+1}, ..., x_{a+k} would have sequence numbers 1, 2,..., k. Since the x_{a+k+1}, ..., x_{n} subsequence have 'sequence' value 1, this would obviously be incorrect. We fix the reordering of the data in the js frontend to be consistent with what is done by the server. Note that this is only pertinent for sequences of reordering moves, since otherwise the data comes directly from the server. opw 1867049
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js8
1 files changed, 7 insertions, 1 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 7621fe35446..16f77b7954c 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -894,8 +894,14 @@ var BasicModel = AbstractModel.extend({
params: params,
})
.then(function () {
+ var offset = options.offset ? options.offset : 0;
+ var old_data = data.data.slice();
data.data = _.sortBy(data.data, function (d) {
- return _.indexOf(resIDs, self.localData[d].res_id);
+ if (_.contains(resIDs, self.localData[d].res_id)) {
+ return _.indexOf(resIDs, self.localData[d].res_id) + offset;
+ } else {
+ return _.indexOf(old_data, d);
+ }
});
data.res_ids = [];
_.each(data.data, function (d) {