From 90279c70ebe02eb2c6dbf452289ace2164ae525e Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 10 Jan 2018 14:36:00 +0100 Subject: [PATCH] [FIX] web: quick create in empty grouped kanban views For kanban views with attribute 'on_create="quick_create' set on their root node, clicking on 'Create' in the control panel should open the quick create widget in the first column if the view is grouped and if there is at least one column displayed. It was working as expected, except when there were no record yet. This was because the kanban controller used the 'state.count' attribute of the state (which indicates the total number of records in the group), whereas it should have used 'state.data.length' (which is the number of columns). --- .../src/js/views/kanban/kanban_controller.js | 7 +-- addons/web/static/tests/views/kanban_tests.js | 43 ++++++++++++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_controller.js b/addons/web/static/src/js/views/kanban/kanban_controller.js index 7b12e6f034c..9e97ec40686 100644 --- a/addons/web/static/src/js/views/kanban/kanban_controller.js +++ b/addons/web/static/src/js/views/kanban/kanban_controller.js @@ -239,15 +239,16 @@ var KanbanController = BasicController.extend({ * @private */ _onButtonNew: function () { - var data = this.model.get(this.handle, {raw: true}); - if (data.groupedBy.length > 0 && data.count > 0 && this.on_create === 'quick_create') { + var state = this.model.get(this.handle, {raw: true}); + var hasColumns = state.groupedBy.length > 0 && state.data.length > 0; + if (hasColumns && this.on_create === 'quick_create') { // Activate the quick create in the first column this.renderer.addQuickCreate(); } else if (this.on_create && this.on_create !== 'quick_create') { // Execute the given action this.do_action(this.on_create, { on_close: this.reload.bind(this), - additional_context: data.context, + additional_context: state.context, }); } else { // Open the form view diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index f10c459baf2..9e6d6e9e30f 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -576,7 +576,6 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - kanban.renderButtons(); assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, "there should be 2 records in first column"); @@ -608,6 +607,48 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('quick create record in empty grouped kanban', function (assert) { + assert.expect(3); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + mockRPC: function (route, args) { + if (args.method === 'read_group') { + // override read_group to return empty groups, as this is + // the case for several models (e.g. project.task grouped + // by stage_id) + var result = [ + {__domain: [['product_id', '=', 3]], product_id_count: 0}, + {__domain: [['product_id', '=', 5]], product_id_count: 0}, + ]; + return $.when(result); + } + return this._super.apply(this, arguments); + }, + }); + + assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + "there should be 2 columns"); + assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + "both columns should be empty"); + + kanban.$buttons.find('.o-kanban-button-new').click(); + + assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_quick_create').length, 1, + "should have opened the quick create in the first column"); + + kanban.destroy(); + }); + QUnit.test('many2many_tags in kanban views', function (assert) { assert.expect(12);