From fe4f63d3259e84e1d64c6f9bf30e184756ab24b4 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Thu, 9 Nov 2017 10:15:57 +0100 Subject: [PATCH] [FIX] web: create in editable grouped list views Before this commit, an issue occured when you tried to create a new record in a editable grouped list view. A new line was created with an undefined group. Editable grouped list views are not supported. So now, we have to switch on the form view when you click on create. This behavior is already implemented when you open an existing record. --- .../static/src/js/views/list/list_controller.js | 4 ++-- addons/web/static/tests/views/list_tests.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 460ad5de100..67cc6271509 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -355,8 +355,8 @@ var ListController = BasicController.extend({ // trigger a click on the main bus, which would be then caught by the // list editable renderer and would unselect the newly created row event.stopPropagation(); - - if (this.editable) { + var state = this.model.get(this.handle, {raw: true}); + if (this.editable && !state.groupedBy.length) { this._addRecord(); } else { this.trigger_up('switch_view', {view_type: 'form', res_id: undefined}); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 0bdb3187406..2b0762aaf82 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -2624,7 +2624,7 @@ QUnit.module('Views', { // Editable grouped list views are not supported, so the purpose of this // test is to check that when a list view is grouped, its editable // attribute is ignored - assert.expect(4); + assert.expect(5); var list = createView({ View: ListView, @@ -2632,8 +2632,9 @@ QUnit.module('Views', { data: this.data, arch: '', intercepts: { - switch_view: function () { - assert.step('switch view'); + switch_view: function (event) { + var resID = event.data.res_id || false; + assert.step('switch view ' + event.data.view_type + ' ' + resID); }, }, }); @@ -2645,9 +2646,15 @@ QUnit.module('Views', { // reload with groupBy list.reload({groupBy: ['bar']}); + + // clicking on record should open the form view list.$('.o_group_header:first').click(); list.$('.o_data_cell:first').click(); - assert.verifySteps(['switch view'], 'one switch view should have been requested'); + + // clicking on create button should open the form view + list.$buttons.find('.o_list_button_add').click(); + assert.verifySteps(['switch view form 1', 'switch view form false'], + 'two switch view to form should have been requested'); list.destroy(); });