From cbcb71247121bc579697f9dc26b4990a28a2be08 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Mon, 19 Jun 2023 05:32:20 +0000 Subject: [PATCH] [FIX] web: keep the possibility of creating a record with form view Issue: ------ When a list view is editable and we add a `Group By`, the create button in the header is no longer available. This is annoying when we are working with default filters and do not have any records. Solution: --------- Add the "New" button in the header of the list view and redirect to the form view when we use it. opw-3304692 closes odoo/odoo#126710 X-original-commit: 8332cca8926a8d032f921b39520227070303fcc5 Signed-off-by: Francois Georis (fge) Signed-off-by: Thomas Lefebvre (thle) --- .../static/src/views/list/list_controller.js | 2 +- .../static/src/views/list/list_controller.xml | 2 +- .../web/static/tests/views/list_view_tests.js | 49 +++++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/views/list/list_controller.js b/addons/web/static/src/views/list/list_controller.js index 7aa5462d6b3..800f20b45a1 100644 --- a/addons/web/static/src/views/list/list_controller.js +++ b/addons/web/static/src/views/list/list_controller.js @@ -202,7 +202,7 @@ export class ListController extends Component { async createRecord({ group } = {}) { const list = (group && group.list) || this.model.root; - if (this.editable) { + if (this.editable && !list.isGrouped) { if (!(list instanceof DynamicRecordList)) { throw new Error("List should be a DynamicRecordList"); } diff --git a/addons/web/static/src/views/list/list_controller.xml b/addons/web/static/src/views/list/list_controller.xml index 6914716996d..a9066f1f0f0 100644 --- a/addons/web/static/src/views/list/list_controller.xml +++ b/addons/web/static/src/views/list/list_controller.xml @@ -5,7 +5,7 @@
- + diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 39dcdfef094..8c1d67ebbb7 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -2861,10 +2861,10 @@ QUnit.module("Views", (hooks) => { await toggleSearchBarMenu(target); await toggleMenuItem(target, "candle"); - assert.containsNone( + assert.containsOnce( target, - ".o_list_button_add", - "Create not available as list is grouped" + ".o_list_button_add:visible", + "Create available as list is grouped" ); assert.containsNone( target, @@ -2874,6 +2874,47 @@ QUnit.module("Views", (hooks) => { } ); + QUnit.test( + "editable list view: check that add button is present when groupby applied", + async function (assert) { + assert.expect(4); + + serverData.models.foo.fields.foo = { string: "Foo", type: "char", required: true }; + serverData.actions = { + 11: { + id: 11, + name: "Partners Action 11", + res_model: "foo", + type: "ir.actions.act_window", + views: [[3, "list"], [4, "form"]], + search_view_id: [9, "search"], + } + }; + serverData.views = { + "foo,3,list": + '', + "foo,4,form": + '
', + "foo,9,search": ` + + + `, + }; + + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 11); + + assert.containsOnce(target, ".o_list_button_add:visible"); + await click(target.querySelector(".o_searchview_dropdown_toggler")); + await click($(target).find('.o_menu_item:contains("candle")')[0]); + assert.containsOnce(target, ".o_list_button_add:visible"); + + assert.containsOnce(target, ".o_list_view"); + await click($(".o_list_button_add:visible").get(0)); + assert.containsOnce(target, ".o_form_view"); + } + ); + QUnit.test("list view not groupable", async function (assert) { serverData.views = { "foo,false,search": ` @@ -13461,7 +13502,7 @@ QUnit.module("Views", (hooks) => { await toggleSearchBarMenu(target); await toggleMenuItem(target, "bar"); - assert.containsNone(target, ".o_list_button_add"); + assert.containsOnce(target, ".o_list_button_add:visible"); // reload without groupby await toggleMenuItem(target, "bar");