diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 9dd7c4d1141..ac7187c3874 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -134,6 +134,9 @@ var x2ManyCommands = { }; var BasicModel = AbstractModel.extend({ + // constants + OPEN_GROUP_LIMIT: 10, // after this limit, groups are automatically folded + // list of models for which the DataManager's cache should be cleared on // create, update and delete operations noCacheModels: [ @@ -3991,6 +3994,7 @@ var BasicModel = AbstractModel.extend({ list.data = []; list.count = 0; var defs = []; + var openGroupCount = 0; _.each(groups, function (group) { var aggregateValues = {}; @@ -4046,7 +4050,7 @@ var BasicModel = AbstractModel.extend({ oldGroup.limit = oldGroup.limit + oldGroup.loadMoreOffset; _.extend(oldGroup, updatedProps); newGroup = oldGroup; - } else if (!newGroup.openGroupByDefault) { + } else if (!newGroup.openGroupByDefault || openGroupCount >= self.OPEN_GROUP_LIMIT) { newGroup.isOpen = false; } else { newGroup.isOpen = '__fold' in group ? !group.__fold : true; @@ -4054,6 +4058,7 @@ var BasicModel = AbstractModel.extend({ list.data.push(newGroup.id); list.count += newGroup.count; if (newGroup.isOpen && newGroup.count > 0) { + openGroupCount++; defs.push(self._load(newGroup, options)); } }); diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 1fbe683187d..66476aaad35 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -2162,6 +2162,72 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('auto fold group when reach the limit', function (assert) { + assert.expect(7); + + var data = this.data; + for (var i = 0; i < 12; i++) { + data.product.records.push({ + id: (8 + i), + name: ("column"), + }); + data.partner.records.push({ + id: (20 + i), + foo: ("dumb entry"), + product_id: (8 + i), + }); + } + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + mockRPC: function (route, args) { + if (args.method === 'read_group') { + return this._super.apply(this, arguments).then(function (result) { + result[2].__fold = true; + result[8].__fold = true; + return result; + }); + } + return this._super(route, args); + }, + }); + + // we look if column are fold/unfold according what is expected + assert.notOk(kanban.$('.o_kanban_group:nth-child(2)').hasClass('o_column_folded'), + 'second column must be unfolded by default'); + assert.notOk(kanban.$('.o_kanban_group:nth-child(4)').hasClass('o_column_folded'), + 'fourth column must be unfolded by default'); + assert.notOk(kanban.$('.o_kanban_group:nth-child(10)').hasClass('o_column_folded'), + 'tenth column must be unfolded by default'); + assert.ok( + kanban.$('.o_kanban_group:nth-child(3)').hasClass('o_column_folded') + && kanban.$('.o_kanban_group:nth-child(9)').hasClass('o_column_folded'), + 'third and ninth columns must be folded by default'); + // we look if columns are actually fold after we reached the limit + assert.ok( + kanban.$('.o_kanban_group:nth-child(13)').hasClass('o_column_folded') + && kanban.$('.o_kanban_group:nth-child(14)').hasClass('o_column_folded'), + 'thirteenth and fourtheenth columns must be folded because we reached the limit'); + // we look if we have the right count of folded/unfolded column + assert.strictEqual( + kanban.$('.o_kanban_group:not(.o_column_folded)').length, + 10, 'must have ten opened columns'); + assert.strictEqual( + kanban.$('.o_kanban_group.o_column_folded').length, + 4, 'must have four folded columns'); + + kanban.destroy(); + }); + QUnit.test('hide and display help message (ESC) in kanban quick create', function (assert) { assert.expect(2); diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 378ba1fd84a..555d939803d 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -983,6 +983,10 @@ non-editable :ref:`form view `. Records may be grouped in columns for use in workflow visualisation or manipulation (e.g. tasks or work-progress management), or ungrouped (used simply to visualize records). +.. note:: The kanban view will load and display a maximum of ten columns. + Any column after that will be closed (but can still be opened by + the user). + The root element of the Kanban view is ````, it can use the following attributes: