From 7e8fa2aac58af79909204f02e75eda04df23b27d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 24 Sep 2015 13:51:41 +0200 Subject: [PATCH] [FIX] web: trigger onchange only once when write re-order sequences --- addons/web/static/src/js/views/list_view.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/list_view.js b/addons/web/static/src/js/views/list_view.js index 095e79eb6ee..20ac68b1439 100644 --- a/addons/web/static/src/js/views/list_view.js +++ b/addons/web/static/src/js/views/list_view.js @@ -1642,23 +1642,25 @@ ListView.Groups = Class.extend( /** @lends instance.web.ListView.Groups# */{ // if drag to 1st row (to = 0), start sequencing from 0 // (exclusive lower bound) seq = to ? list.records.at(to - 1).get(seqname) : 0; + var defs = []; var fct = function (dataset, id, seq) { - $.async_when().done(function () { + defs.push($.async_when().then(function () { var attrs = {}; attrs[seqname] = seq; - dataset.write(id, attrs); - }); + return dataset.write(id, attrs, {internal_dataset_changed: true}); + })); }; while (++seq, (record = list.records.at(index++))) { // write are independent from one another, so we can just // launch them all at the same time and we don't really // give a fig about when they're done - // FIXME: breaks on o2ms (e.g. Accounting > Financial - // Accounting > Taxes > Taxes, child tax accounts) - // when synchronous (without setTimeout) fct(dataset, record.get('id'), seq); record.set(seqname, seq); } + $.when.apply($, defs).then(function () { + // use internal_dataset_changed and trigger one onchange after all writes + dataset.trigger("dataset_changed"); + }); } }); },