diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 324ff6672bbff..71b8a690065fa 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -847,6 +847,13 @@ function makeActionManager(env) { * @param {ActionOptions} options */ async function _executeReportAction(action, options) { + const handlers = registry.category("ir.actions.report handlers").getAll(); + for (const handler of handlers) { + const result = await handler(action, options, env); + if (result) { + return result; + } + } if (action.report_type === "qweb-html") { return _executeReportClientAction(action, options); } else if (action.report_type === "qweb-pdf") { diff --git a/addons/web/static/tests/webclient/actions/report_action_tests.js b/addons/web/static/tests/webclient/actions/report_action_tests.js index d4b7400cd0a47..4660ed9d71504 100644 --- a/addons/web/static/tests/webclient/actions/report_action_tests.js +++ b/addons/web/static/tests/webclient/actions/report_action_tests.js @@ -274,4 +274,41 @@ QUnit.module("ActionManager", (hooks) => { ui.bus.off("UNBLOCK", webClient); } ); + + QUnit.test("can use custom handlers for report actions", async function (assert) { + assert.expect(8); + mockDownload((options) => { + assert.step(options.url); + return Promise.resolve(); + }); + const mockRPC = async (route, args) => { + assert.step((args && args.method) || route); + if (route === "/report/check_wkhtmltopdf") { + return "ok"; + } + }; + const webClient = await createWebClient({ testConfig, mockRPC }); + let customHandlerCalled = false; + registry.category("ir.actions.report handlers").add("custom_handler", async action => { + if (action.id === 7 && !customHandlerCalled) { + customHandlerCalled = true; + assert.step("calling custom handler"); + return true; + } + assert.step("falling through to default handler"); + }); + await doAction(webClient, 7); + assert.step("first doAction finished"); + await doAction(webClient, 7); + + assert.verifySteps([ + "/web/webclient/load_menus", + "/web/action/load", + "calling custom handler", + "first doAction finished", + "falling through to default handler", + "/report/check_wkhtmltopdf", + "/report/download", + ]); + }); });