[FIX] web: KanbanModel: resequence
There were several issues with the resequence method. First the lookup in the model's fields to determine if there is a 'sequence' field (to know whether or not an RPC should be done) was incorrect when resequencing columns as the lookup was done for the wrong model. Actually, we don't have the list of fields of the related model, so this lookup shouldn't exist at all, and the RPC should be done in all cases (the controller correctly handles the absence of 'sequence' field). Second, the JS sort of the data didn't work either as we didn't manipulate the dataPoints but only their ids (the internal representation of the dataPoints is flat, so the data of elements of type 'list' only contains the id of its dataPoints).
This commit is contained in:
@@ -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;
|
||||
});
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -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: '<kanban>' +
|
||||
'<field name="product_id"/>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div><field name="foo"/></div>' +
|
||||
'</t></templates>' +
|
||||
'</kanban>',
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user