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 9bb728011e8..cbe31e5938f 100644
--- a/addons/web/static/src/js/views/kanban/kanban_controller.js
+++ b/addons/web/static/src/js/views/kanban/kanban_controller.js
@@ -40,8 +40,7 @@ var KanbanController = BasicController.extend({
this.on_create = params.on_create;
this.hasButtons = params.hasButtons;
- // true iff grouped by an m2o field and group_create action enabled
- this.create_column_enabled = false;
+ this.createColumnEnabled = this._isCreateColumnEnabled();
},
//--------------------------------------------------------------------------
@@ -60,16 +59,12 @@ var KanbanController = BasicController.extend({
}
},
/**
- * Override update method to recompute create_column_enabled.
+ * Override update method to recompute createColumnEnabled.
*
* @returns {Deferred}
*/
update: function () {
- var state = this.model.get(this.handle, {raw: true});
- var group_by_field = state.fields[state.groupedBy[0]];
- var grouped_by_m2o = group_by_field && (group_by_field.type === 'many2one');
- var groupCreate = this.is_action_enabled('group_create');
- this.create_column_enabled = grouped_by_m2o && groupCreate;
+ this.createColumnEnabled = this._isCreateColumnEnabled();
return this._super.apply(this, arguments);
},
@@ -95,9 +90,26 @@ var KanbanController = BasicController.extend({
*/
_hasContent: function (state) {
return this._super.apply(this, arguments) ||
- this.create_column_enabled ||
+ this.createColumnEnabled ||
(state.groupedBy.length && state.data.length);
},
+ /**
+ * The column quick create should be displayed in kanban iff grouped by an
+ * m2o field and group_create action enabled.
+ *
+ * @returns {Boolean}
+ */
+ _isCreateColumnEnabled: function () {
+ var groupCreate = this.is_action_enabled('group_create');
+ if (!groupCreate) {
+ // pre-return to avoid a lot of the following processing
+ return false;
+ }
+ var state = this.model.get(this.handle, {raw: true});
+ var groupByField = state.fields[state.groupedBy[0]];
+ var groupedByM2o = groupByField && (groupByField.type === 'many2one');
+ return groupedByM2o;
+ },
/**
* This method calls the server to ask for a resequence. Note that this
* does not rerender the user interface, because in most case, the
@@ -119,7 +131,7 @@ var KanbanController = BasicController.extend({
_updateButtons: function () {
if (this.$buttons) {
var data = this.model.get(this.handle, {raw: true});
- var create_muted = data.count === 0 && this.create_column_enabled;
+ var create_muted = data.count === 0 && this.createColumnEnabled;
this.$buttons.find('.o-kanban-button-new')
.toggleClass('btn-primary', !create_muted)
.toggleClass('btn-default', create_muted);
diff --git a/addons/web/static/src/js/views/kanban/kanban_view.js b/addons/web/static/src/js/views/kanban/kanban_view.js
index 190647037d5..55a90e83242 100644
--- a/addons/web/static/src/js/views/kanban/kanban_view.js
+++ b/addons/web/static/src/js/views/kanban/kanban_view.js
@@ -34,6 +34,7 @@ var KanbanView = BasicView.extend({
var activeActions = this.controllerParams.activeActions;
activeActions = _.extend(activeActions, {
+ group_create: arch.attrs.group_create ? JSON.parse(arch.attrs.group_create) : true,
group_edit: arch.attrs.group_edit ? JSON.parse(arch.attrs.group_edit) : true,
group_delete: arch.attrs.group_delete ? JSON.parse(arch.attrs.group_delete) : true,
});
@@ -41,7 +42,7 @@ var KanbanView = BasicView.extend({
this.rendererParams.column_options = {
editable: activeActions.group_edit,
deletable: activeActions.group_delete,
- group_creatable: true,
+ group_creatable: activeActions.group_create,
quick_create: params.isQuickCreateEnabled || this._isQuickCreateEnabled(viewInfo),
};
this.rendererParams.record_options = {
diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js
index d804ab35d71..8141d8c8f79 100644
--- a/addons/web/static/tests/views/kanban_tests.js
+++ b/addons/web/static/tests/views/kanban_tests.js
@@ -913,6 +913,72 @@ QUnit.module('Views', {
kanban.destroy();
});
+ QUnit.test('no nocontent helper for grouped kanban with no records', function (assert) {
+ assert.expect(4);
+
+ this.data.partner.records = [];
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '' +
+ '' +
+ '
' +
+ '' +
+ '',
+ groupBy: ['product_id'],
+ viewOptions: {
+ action: {
+ help: "No content helper",
+ },
+ },
+ });
+
+ assert.strictEqual(kanban.$('.o_kanban_group').length, 0,
+ "there should be no columns");
+ assert.strictEqual(kanban.$('.o_kanban_record').length, 0,
+ "there should be no records");
+ assert.strictEqual(kanban.$('.oe_view_nocontent').length, 0,
+ "there should be no nocontent helper");
+ assert.strictEqual(kanban.$('.o_column_quick_create').length, 1,
+ "there should be a column quick create");
+ kanban.destroy();
+ });
+
+ QUnit.test('nocontent helper for grouped kanban with no records with no group_create', function (assert) {
+ assert.expect(4);
+
+ this.data.partner.records = [];
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '' +
+ '' +
+ '
' +
+ '' +
+ '',
+ groupBy: ['product_id'],
+ viewOptions: {
+ action: {
+ help: "No content helper",
+ },
+ },
+ });
+
+ assert.strictEqual(kanban.$('.o_kanban_group').length, 0,
+ "there should be no columns");
+ assert.strictEqual(kanban.$('.o_kanban_record').length, 0,
+ "there should be no records");
+ assert.strictEqual(kanban.$('.oe_view_nocontent').length, 1,
+ "there should be a nocontent helper");
+ assert.strictEqual(kanban.$('.o_column_quick_create').length, 0,
+ "there should not be a column quick create");
+ kanban.destroy();
+ });
+
QUnit.test('buttons with modifiers', function (assert) {
assert.expect(2);