From c2f6189eed24d6d71908469d7941777bb5a48e34 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Mon, 26 Dec 2022 10:02:26 +0000 Subject: [PATCH] [FIX] web: keep props resId on restore breadcrumb **Before this commit** When a breadcrumb is restored, the props resId is overwritten by the res_id of the action. **After this commit** The props resId is kept if it is defined. closes odoo/odoo#108996 X-original-commit: 810a1d29bfa7c497627a37e0cec64df51b75bb4b Signed-off-by: Aaron Bohy (aab) --- .../src/webclient/actions/action_service.js | 2 +- .../views/fields/one2many_field_tests.js | 3 +- .../webclient/actions/window_action_tests.js | 82 +++++++++++++++++-- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index c031c65a319..ce15406bd1d 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -502,7 +502,7 @@ function makeActionManager(env) { } // view specific - if (action.res_id) { + if (action.res_id && !viewProps.resId) { viewProps.resId = action.res_id; } diff --git a/addons/web/static/tests/views/fields/one2many_field_tests.js b/addons/web/static/tests/views/fields/one2many_field_tests.js index 981c8b1ae50..9f4f2bf043a 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -10863,7 +10863,6 @@ QUnit.module("Fields", (hooks) => { 1: { id: 1, name: "test", - res_id: 1, res_model: "partner", type: "ir.actions.act_window", views: [ @@ -10900,7 +10899,7 @@ QUnit.module("Fields", (hooks) => { "10", ]); - await click(target.querySelector(".o_data_cell")); + await click(target, ".o_data_row:nth-child(3) .o_data_cell"); assert.containsOnce(target, ".o_form_view"); assert.deepEqual( getNodesTextContent(target.querySelectorAll(".o_data_cell")), diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 764f4dc19ae..1beef63ea31 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -582,21 +582,25 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("A new form view can be reloaded after a failed one", async function (assert) { assert.expect(5); - const webClient = await createWebClient({serverData}); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); await cpHelpers.switchView(target, "list"); assert.containsOnce(target, ".o_list_view", "The list view should be displayed"); // Click on the first record - await testUtils.dom.click($(target).find(".o_list_view .o_data_row:first .o_data_cell:first")); + await testUtils.dom.click( + $(target).find(".o_list_view .o_data_row:first .o_data_cell:first") + ); await legacyExtraNextTick(); assert.containsOnce(target, ".o_form_view", "The form view should be displayed"); // Delete the current record await testUtils.controlPanel.toggleActionMenu(target); await testUtils.dom.click( - Array.from(document.querySelectorAll('.o_menu_item')).find(e => e.textContent === "Delete") + Array.from(document.querySelectorAll(".o_menu_item")).find( + (e) => e.textContent === "Delete" + ) ); await legacyExtraNextTick(); assert.containsOnce(target, ".modal", "a confirm modal should be displayed"); @@ -623,10 +627,15 @@ QUnit.module("ActionManager", (hooks) => { await legacyExtraNextTick(); assert.containsOnce(target, ".o_list_view", "should still display the list view"); - await testUtils.dom.click($(target).find(".o_list_view .o_data_row:first .o_data_cell:first")); + await testUtils.dom.click( + $(target).find(".o_list_view .o_data_row:first .o_data_cell:first") + ); await legacyExtraNextTick(); - assert.containsOnce(target, ".o_form_view", - "The form view should still load after a previous failed update | reload"); + assert.containsOnce( + target, + ".o_form_view", + "The form view should still load after a previous failed update | reload" + ); }); QUnit.test("there is no flickering when switching between views", async function (assert) { @@ -1945,6 +1954,67 @@ QUnit.module("ActionManager", (hooks) => { } ); + QUnit.test( + "action with res_id, load another id on current action, do new action, restore previous", + async (assert) => { + serverData.actions[999] = { + id: 999, + name: "Partner", + res_model: "partner", + type: "ir.actions.act_window", + res_id: 1, + views: [[44, "form"]], + }; + serverData.views["partner,44,form"] = + '
'; + const mockRPC = async (route, { method }) => { + if (method === "get_formview_action") { + return Promise.resolve({ ...serverData.actions[999], res_id: 3 }); + } + }; + const webClient = await createWebClient({ serverData, mockRPC }); + await doAction(webClient, 999, { props: { resIds: [1, 2] } }); + assert.containsOnce(target, ".o_form_view .o_form_editable"); + assert.strictEqual( + target.querySelector(".o_control_panel .breadcrumb").textContent, + "First record" + ); + assert.strictEqual( + target.querySelector(".o_control_panel .o_pager_counter").textContent, + "1 / 2" + ); + + // load another id on current action (through pager) + await click(target.querySelector(".o_pager_next")); + assert.strictEqual( + target.querySelector(".o_control_panel .breadcrumb").textContent, + "Second record" + ); + assert.strictEqual( + target.querySelector(".o_control_panel .o_pager_counter").textContent, + "2 / 2" + ); + + // push another action in the breadcrumb + await click(target, ".o_field_many2one .o_external_button"); + assert.strictEqual( + target.querySelector(".o_control_panel .breadcrumb").textContent, + "Second recordThird record" + ); + + // restore previous action through breadcrumb + await click(target.querySelector(".o_control_panel .breadcrumb a")); + assert.strictEqual( + target.querySelector(".o_control_panel .breadcrumb").textContent, + "Second record" + ); + assert.strictEqual( + target.querySelector(".o_control_panel .o_pager_counter").textContent, + "2 / 2" + ); + } + ); + QUnit.test("open a record, come back, and create a new record", async function (assert) { assert.expect(7); const webClient = await createWebClient({ serverData });