From 6663ff97b66fb3169f36bbc44e6bcffa5715c228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 13 Sep 2018 17:53:12 +0200 Subject: [PATCH] [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. --- .../src/js/views/kanban/kanban_column.js | 1 + .../static/src/js/views/kanban/kanban_view.js | 1 + addons/web/static/src/xml/kanban.xml | 2 +- addons/web/static/tests/views/kanban_tests.js | 71 ++++++++++++++++++- doc/reference/views.rst | 3 + 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_column.js b/addons/web/static/src/js/views/kanban/kanban_column.js index 6fea1c36d32..ef75caca8c0 100644 --- a/addons/web/static/src/js/views/kanban/kanban_column.js +++ b/addons/web/static/src/js/views/kanban/kanban_column.js @@ -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; 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 99be6175da3..791e3664668 100644 --- a/addons/web/static/src/js/views/kanban/kanban_view.js +++ b/addons/web/static/src/js/views/kanban/kanban_view.js @@ -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, diff --git a/addons/web/static/src/xml/kanban.xml b/addons/web/static/src/xml/kanban.xml index adc213999f2..b91b8844752 100644 --- a/addons/web/static/src/xml/kanban.xml +++ b/addons/web/static/src/xml/kanban.xml @@ -23,7 +23,7 @@ Edit Stage Delete - + Archive All Unarchive All diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index c967b42a332..1fbe683187d 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -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: '' + + '' + + '' + + '' + + '
' + + '
', + 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: '' + + '' + + '' + + '' + + '
' + + '
', + 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); diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 052c63a97f5..373a31b022a 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -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