[FIX] web: Kanban: correctly destroy old widget after update

The attribute `widgets` has been renamed in rev https://github.com/odoo/odoo/commit/7ff8aa73e17b281b3e2bc4c7275d020eab0204e7#commitcomment-22116249
However, KanbanRenderer still uses a `widgets` attribute, not for the fields
widgets but for its columns (or records if ungrouped).

These widgets weren't correctly destroyed since then.

This was causing an issue when you were trying to quick create a record after a
column creation (that generates an update): the quick create was added in the
first old column (which was not in the DOM anymore) so you couldn't see it.
This commit is contained in:
Martin Geubelle
2017-05-15 14:55:21 +02:00
parent feb4a8986d
commit 2fb4cf46d2
2 changed files with 12 additions and 3 deletions
@@ -269,6 +269,8 @@ var KanbanRenderer = BasicRenderer.extend({
* @private
*/
_renderView: function () {
var oldWidgets = this.widgets;
this.widgets = [];
var isGrouped = !!this.state.groupedBy.length;
this.$el.toggleClass('o_kanban_grouped', isGrouped);
this.$el.toggleClass('o_kanban_ungrouped', !isGrouped);
@@ -281,7 +283,7 @@ var KanbanRenderer = BasicRenderer.extend({
this._renderUngrouped(fragment);
}
this.$el.append(fragment);
return this._super.apply(this, arguments);
return this._super.apply(this, arguments).then(_.invoke.bind(_, oldWidgets, 'destroy'));
},
});
@@ -586,7 +586,7 @@ QUnit.module('Views', {
});
QUnit.test('create a column in grouped on m2o', function (assert) {
assert.expect(12);
assert.expect(13);
var nbRPCs = 0;
var kanban = createView({
@@ -645,6 +645,11 @@ QUnit.module('Views', {
assert.ok(!kanban.$('.o_kanban_group:last').hasClass('o_column_folded'),
'the created column should not be folded');
assert.strictEqual(nbRPCs, 0, 'no rpc should have been done when folding/unfolding');
// quick create a record
kanban.$buttons.find('.o-kanban-button-new').click(); // Click on 'Create'
assert.ok(kanban.$('.o_kanban_group:first() > div:nth(1)').hasClass('o_kanban_quick_create'),
"clicking on create should open the quick_create in the first column");
kanban.destroy();
});
@@ -680,7 +685,7 @@ QUnit.module('Views', {
}),
QUnit.test('delete a column in grouped on m2o', function (assert) {
assert.expect(25);
assert.expect(26);
var kanban = createView({
View: KanbanView,
@@ -750,6 +755,8 @@ QUnit.module('Views', {
assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive').length,
"should not be able to restore the records");
assert.verifySteps(['read_group', 'unlink', 'read_group']);
assert.strictEqual(kanban.renderer.widgets.length, 2,
"the old widgets should have been correctly deleted");
kanban.destroy();
});