[IMP] web: add an option to hide archive option in kanban columns

Currently kanban columns propose an Archive / Unarchive option if the
records model has an active field. It allows to directly archive or
restore all records belonging to that column. It is currently not possible
to control whether this option is present or not as it only depends on the
active field being defined on the model.

In some specific cases we want to be able to hide this option even if the
active field exists. For example future commits will hide this option for
leads (crm.lead) as business flow goes through marking them as won or lost
instead of archiving / restoring them.

This commit adds support of a new archivable parameter when defining the
kanban view that hides the archive buttons if it is set to False. Default
value is true so that current behavior is kept as it is by default.

Doc and tests are added.

This commit is linked to task ID 1880051 and PR #26977.
This commit is contained in:
Thibault Delavallée
2018-09-21 11:22:01 +02:00
parent da03aa3138
commit 6663ff97b6
5 changed files with 76 additions and 2 deletions
@@ -53,6 +53,7 @@ var KanbanColumn = Widget.extend({
this.grouped_by_m2o = options.grouped_by_m2o;
this.editable = options.editable;
this.deletable = options.deletable;
this.archivable = options.archivable;
this.draggable = options.draggable;
this.KanbanRecord = options.KanbanRecord || KanbanRecord; // the KanbanRecord class to use
this.records_editable = options.records_editable;
@@ -61,6 +61,7 @@ var KanbanView = BasicView.extend({
this.rendererParams.column_options = {
editable: activeActions.group_edit,
deletable: activeActions.group_delete,
archivable: this.arch.attrs.archivable ? JSON.parse(this.arch.attrs.archivable) : true,
group_creatable: activeActions.group_create && !config.device.isMobile,
quick_create: params.isQuickCreateEnabled || this._isQuickCreateEnabled(),
quickCreateView: this.arch.attrs.quick_create_view || null,
+1 -1
View File
@@ -23,7 +23,7 @@
<a t-if="widget.editable and widget.id" role="menuitem" class="dropdown-item o_column_edit" href="#">Edit Stage</a>
<a t-if="widget.deletable and widget.id" role="menuitem" class="dropdown-item o_column_delete" href="#">Delete</a>
</t>
<t t-if="widget.has_active_field">
<t t-if="widget.has_active_field and widget.archivable">
<a href="#" class="dropdown-item o_column_archive_records">Archive All</a>
<a href="#" class="dropdown-item o_column_unarchive_records">Unarchive All</a>
</t>
+70 -1
View File
@@ -148,7 +148,7 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('basic grouped rendering with active field', function (assert) {
QUnit.test('basic grouped rendering with active field (archivable by default)', function (assert) {
assert.expect(9);
// add active field on partner model and make all records active
@@ -193,6 +193,75 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('basic grouped rendering with active field and archive enabled (archivable true)', function (assert) {
assert.expect(7);
// add active field on partner model and make all records active
this.data.partner.fields.active = {string: 'Active', type: 'char', default: true};
var envIDs = [1, 2, 3, 4]; // the ids that should be in the environment during this test
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test" archivable="true">' +
'<field name="active"/>' +
'<field name="bar"/>' +
'<templates><t t-name="kanban-box">' +
'<div><field name="foo"/></div>' +
'</t></templates></kanban>',
groupBy: ['bar'],
});
// check archive/restore all actions in kanban header's config dropdown
assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_column_archive_records').length, "should be able to archive all the records");
assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive_records').length, "should be able to restore all the records");
// archive the records of the first column
assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3,
"last column should contain 3 records");
envIDs = [4];
kanban.$('.o_kanban_group:last .o_column_archive_records').click(); // Click on 'Archive All'
assert.ok($('.modal').length, 'a confirm modal should be displayed');
$('.modal-footer .btn-secondary').click(); // Click on 'Cancel'
assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3, "still last column should contain 3 records");
kanban.$('.o_kanban_group:last .o_column_archive_records').click();
assert.ok($('.modal').length, 'a confirm modal should be displayed');
$('.modal-footer .btn-primary').click(); // Click on 'Ok'
assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 0, "last column should not contain any records");
kanban.destroy();
});
QUnit.test('basic grouped rendering with active field and hidden archive buttons (archivable false)', function (assert) {
assert.expect(2);
// add active field on partner model and make all records active
this.data.partner.fields.active = {string: 'Active', type: 'char', default: true};
var envIDs = [1, 2, 3, 4]; // the ids that should be in the environment during this test
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test" archivable="false">' +
'<field name="active"/>' +
'<field name="bar"/>' +
'<templates><t t-name="kanban-box">' +
'<div><field name="foo"/></div>' +
'</t></templates></kanban>',
groupBy: ['bar'],
});
// check archive/restore all actions in kanban header's config dropdown
assert.strictEqual(
kanban.$('.o_kanban_header:first .o_kanban_config .o_column_archive_records').length, 0,
"should not be able to archive all the records");
assert.strictEqual(
kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive_records').length, 0,
"should not be able to restore all the records");
kanban.destroy();
});
QUnit.test('pager should be hidden in grouped mode', function (assert) {
assert.expect(1);
+3
View File
@@ -998,6 +998,9 @@ attributes:
whether groups can be deleted via the context menu. Default: true.
``group_edit``
whether groups can be edited via the context menu. Default: true.
``archivable``
whether records belonging to a column can be archived / restored if an
``active`` field is defined on the model. Default: true.
``quick_create``
whether it should be possible to create records without switching to the
form view. By default, ``quick_create`` is enabled when the Kanban view is