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