From 49b35e85ca93d8dffbc8a1273bf49a0e34dddb03 Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Tue, 5 Oct 2021 11:32:51 +0000 Subject: [PATCH] [FIX] web: do not clearUncommittedChanges for function actions Before this commit: In res.config.settings form view when user change something in form and click on button in form then it will display to save the unsaved changes, when we click 'Save' button from dialog still dialog remain there it is not closed(while record is saved in background, just dialog is not closed) This is because we called 'clearUncommittedChanges' method before executing client action, 'Save' button on dialog returns client action for reload page but as we calling 'clearUncommittedChanges' so it will call 'canBeDiscarded' method of 'BaseSettingController' which again show dialog for unsaved changes. After this commit: unsaved changes dialog is closed on clicking 'Save' button from dialog, we called 'clearUncommittedChanges' method only if clientAction is instance of Component, i.e. if client action is type of function which is our case, reload is client action which type of function so in that case we do not need to call 'clearUncommittedChanges'. task-2662302 closes odoo/odoo#78035 X-original-commit: 5d8376a8f9a8957112afb35854bdb8b050bd6903 Signed-off-by: Aaron Bohy (aab) --- .../src/webclient/actions/action_service.js | 10 +++++----- .../webclient/actions/client_action_tests.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 2b53fca6f62..b22daaed2e3 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -841,8 +841,11 @@ function makeActionManager(env) { async function _executeClientAction(action, options) { const clientAction = actionRegistry.get(action.tag); if (clientAction.prototype instanceof Component) { - if (action.target !== "new" && clientAction.target) { - action.target = clientAction.target; + if (action.target !== "new") { + await clearUncommittedChanges(env); + if (clientAction.target) { + action.target = clientAction.target; + } } const controller = { jsId: `controller_${++id}`, @@ -1078,9 +1081,6 @@ function makeActionManager(env) { case "ir.actions.act_window_close": return _executeCloseAction({ onClose: options.onClose, onCloseInfo: action.infos }); case "ir.actions.client": - if (action.target !== "new") { - await clearUncommittedChanges(env); - } return _executeClientAction(action, options); case "ir.actions.report": return _executeReportAction(action, options); diff --git a/addons/web/static/tests/webclient/actions/client_action_tests.js b/addons/web/static/tests/webclient/actions/client_action_tests.js index 9dd9f8349a2..3f690a6fea5 100644 --- a/addons/web/static/tests/webclient/actions/client_action_tests.js +++ b/addons/web/static/tests/webclient/actions/client_action_tests.js @@ -131,6 +131,25 @@ QUnit.module("ActionManager", (hooks) => { assert.containsOnce(webClient, ".o_kanban_view"); }); + QUnit.test( + "'CLEAR-UNCOMMITTED-CHANGES' is not triggered for function client actions", + async function (assert) { + assert.expect(2); + + registry.category("actions").add("my_action", async () => { + assert.step("my_action"); + }); + + const webClient = await createWebClient({ serverData }); + webClient.env.bus.on("CLEAR-UNCOMMITTED-CHANGES", webClient, () => { + assert.step("CLEAR-UNCOMMITTED-CHANGES"); + }); + + await doAction(webClient, "my_action"); + assert.verifySteps(["my_action"]); + } + ); + QUnit.test("client action with control panel (legacy)", async function (assert) { assert.expect(4); // LPE Fixme: at this time we don't really know the API that wowl ClientActions implement