[FIX] web: archive kanban column

When we try to archive a kanban column we get a traceback when the field
'active' exists on the model but not in the view.

This traceback is caused by an unecessary check of the active value of
the record.

To fix it, we apply the 'active' value on all records, and not only on
the ones where active value changed.
This commit is contained in:
Pierre Masereel
2017-04-14 10:50:35 +02:00
parent 2f67881d45
commit ff2ce7524b
2 changed files with 38 additions and 6 deletions
@@ -182,12 +182,7 @@ var KanbanController = BasicController.extend({
var self = this;
var active_value = !event.data.archive;
var column = event.target;
var record_ids = [];
_.each(column.records, function (kanban_record) {
if (kanban_record.record.active.value !== active_value) {
record_ids.push(kanban_record.db_id);
}
});
var record_ids = _.pluck(column.records, 'db_id');
if (record_ids.length) {
this.model
.toggleActive(record_ids, active_value, column.db_id)
@@ -1119,6 +1119,43 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('archive kanban column, when active field is not in the view', function (assert) {
assert.expect(3);
this.data.partner.fields.active = {string: 'Active', type: 'char', default: true};
var writeOnActive;
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, args) {
if (args.method === 'write' && 'active' in args.args[1]) {
writeOnActive = true;
}
return this._super.apply(this, arguments);
},
});
var $first_column = kanban.$('.o_kanban_group:first()');
assert.strictEqual($first_column.find('.o_kanban_record').length, 2,
"there should be 2 partners in first column");
$first_column.find('.o_column_archive').click();
assert.ok(writeOnActive, "should write on the active field");
assert.strictEqual($first_column.find('.o_kanban_record').length, 0,
"there should not be partners anymore");
kanban.destroy();
});
});
});