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;