From 7b948a731f08073e2c088baa4e8631cfffaf9b1c Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Mon, 17 Oct 2022 09:27:04 +0000 Subject: [PATCH] [FIX] web: discard rejected reloadProms in magicReload Steps to reproduce: - Go to a list view with multiple items - Click on an item - Delete it - Go back in history twice (Using the browser navigation) to return to the list view -> We can't click on another record opw-2854113 closes odoo/odoo#103808 X-original-commit: 92c90823139b413c8289d1c323ad694fc8220a61 Signed-off-by: Hubert Van De Walle Signed-off-by: Aaron Bohy (aab) --- .../web/static/src/legacy/action_adapters.js | 4 +- .../webclient/actions/window_action_tests.js | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/legacy/action_adapters.js b/addons/web/static/src/legacy/action_adapters.js index 2f48aa6d010..b95a51c64ea 100644 --- a/addons/web/static/src/legacy/action_adapters.js +++ b/addons/web/static/src/legacy/action_adapters.js @@ -263,7 +263,7 @@ function useMagicLegacyReload() { widget.reload = function (...args) { manualReload = true; legacyReloadProm = controllerReload.call(widget, ...args); - return legacyReloadProm.then(() => { + return legacyReloadProm.finally(() => { if (manualReload) { legacyReloadProm = null; manualReload = false; @@ -277,7 +277,7 @@ function useMagicLegacyReload() { if (manualUpdate) { legacyReloadProm = updateProm; } - return updateProm.then(() => { + return updateProm.finally(() => { if (manualUpdate) { legacyReloadProm = null; } 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 408b67bb52e..9e4616885e0 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -580,6 +580,55 @@ QUnit.module("ActionManager", (hooks) => { assert.containsN(target, ".o_data_row", 5); }); + QUnit.test("A new form view can be reloaded after a failed one", async function (assert) { + assert.expect(5); + 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 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") + ); + await legacyExtraNextTick(); + assert.containsOnce(target, ".modal", "a confirm modal should be displayed"); + await testUtils.dom.click(target.querySelector(".modal-footer button.btn-primary")); + await legacyExtraNextTick(); + + // The form view is automatically switched to the next record + // Go back to the previous (now deleted) record + webClient.env.bus.trigger("test:hashchange", { + model: "partner", + id: 1, + action: 3, + view_type: "form", + }); + await legacyExtraNextTick(); + + // Go back to the list view + webClient.env.bus.trigger("test:hashchange", { + model: "partner", + action: 3, + view_type: "list", + }); + await legacyExtraNextTick(); + 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 legacyExtraNextTick(); + 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) { assert.expect(20); let def;