[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).
This commit is contained in:
Aaron Bohy
2018-01-12 08:13:15 +01:00
parent 25b101f15b
commit 90279c70eb
2 changed files with 46 additions and 4 deletions
@@ -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
+42 -1
View File
@@ -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: '<kanban on_create="quick_create">' +
'<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 === '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);