Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions addons/web/static/src/webclient/actions/action_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
37 changes: 37 additions & 0 deletions addons/web/static/tests/webclient/actions/report_action_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]);
});
});