diff --git a/addons/web/static/src/js/views/kanban/kanban_model.js b/addons/web/static/src/js/views/kanban/kanban_model.js index 454349a88c5..394ff80b234 100644 --- a/addons/web/static/src/js/views/kanban/kanban_model.js +++ b/addons/web/static/src/js/views/kanban/kanban_model.js @@ -153,19 +153,16 @@ var KanbanModel = BasicModel.extend({ return $.when(parentID); // there is nothing to sort } var self = this; - var data = self.localData[parentID]; - var def; - if (data.fields.sequence) { - def = this._rpc('/web/dataset/resequence') - .params({model: modelName, ids: resIDs}) - .exec(); - } - return $.when(def).then(function () { - data.data = _.sortBy(data.data, function (d) { - return _.indexOf(resIDs, d.res_id); + var data = this.localData[parentID]; + return this._rpc('/web/dataset/resequence') + .params({model: modelName, ids: resIDs}) + .exec() + .then(function () { + data.data = _.sortBy(data.data, function (d) { + return _.indexOf(resIDs, self.localData[d].res_id); + }); + return parentID; }); - return parentID; - }); }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/test/views/kanban_model_tests.js b/addons/web/static/test/views/kanban_model_tests.js index b6ef91aa75a..7c64b7dcf6a 100644 --- a/addons/web/static/test/views/kanban_model_tests.js +++ b/addons/web/static/test/views/kanban_model_tests.js @@ -185,6 +185,69 @@ QUnit.module('Views', { }); }); + QUnit.test('resequence columns and records', function (assert) { + var done = assert.async(); + assert.expect(8); + + this.data.partner.records.push({id: 3, foo: 'aaa', product_id: 37}); + + var nbReseq = 0; + var model = createModel({ + Model: KanbanModel, + data: this.data, + mockRPC: function (route, args) { + if (route === '/web/dataset/resequence') { + nbReseq++; + if (nbReseq === 1) { // resequencing columns + assert.deepEqual(args.ids, [41, 37], + "ids should be correct"); + assert.strictEqual(args.model, 'product_id', + "model should be correct"); + } else if (nbReseq === 2) { // resequencing records + assert.deepEqual(args.ids, [3, 1], + "ids should be correct"); + assert.strictEqual(args.model, 'partner', + "model should be correct"); + } + return $.when(); + } + return this._super.apply(this, arguments); + }, + }); + var params = _.extend(this.params, { + groupedBy: ['product_id'], + fieldNames: ['foo'], + }); + + model.load(params) + .then(function (stateID) { + var state = model.get(stateID); + assert.strictEqual(state.data[0].res_id, 37, + "first group should be res_id 37"); + + // resequence columns + return model.resequence('product_id', [41, 37], stateID); + }) + .then(function (stateID) { + var state = model.get(stateID); + assert.strictEqual(state.data[0].res_id, 41, + "first group should be res_id 41 after resequencing"); + assert.strictEqual(state.data[1].data[0].res_id, 1, + "first record should be res_id 1"); + + // resequence records + return model.resequence('partner', [3, 1], state.data[1].id); + }) + .then(function (groupID) { + var group = model.get(groupID); + assert.strictEqual(group.data[0].res_id, 3, + "first record should be res_id 3 after resequencing"); + + model.destroy(); + done(); + }); + + }); }); }); diff --git a/addons/web/static/test/views/kanban_tests.js b/addons/web/static/test/views/kanban_tests.js index ab67c103526..5878dc3dbb9 100644 --- a/addons/web/static/test/views/kanban_tests.js +++ b/addons/web/static/test/views/kanban_tests.js @@ -995,6 +995,47 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('resequence columns in grouped by m2o', function (assert) { + assert.expect(4); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + mockRPC: function (route) { + if (route === '/web/dataset/resequence') { + return $.when(); + } + return this._super.apply(this, arguments); + }, + }); + + assert.ok(kanban.$('.o_kanban_view').hasClass('ui-sortable'), + "columns should be sortable"); + assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + "should have two columns"); + assert.strictEqual(kanban.$('.o_kanban_group:first').data('id'), 3, + "first column should be id 3 before resequencing"); + + // there is a 100ms delay on the d&d feature (jquery sortable) for + // kanban columns, making it hard to test. So we rather bypass the d&d + // for this test, and directly call the event handler + kanban._onResequenceColumn({data: {ids: [5, 3]}}); + kanban.update({}, {reload: false}); // re-render without reloading + + assert.strictEqual(kanban.$('.o_kanban_group:first').data('id'), 5, + "first column should be id 5 before resequencing"); + + kanban.destroy(); + }); + }); });