Skip to content

Commit 4ca2528

Browse files
sdegueldreaab-odoo
authored andcommitted
[IMP] web: add support for custom handlers for ir.actions.report
closes #873 Related: odoo-dev/enterprise#144 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
1 parent 4d1f71f commit 4ca2528

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

addons/web/static/src/webclient/actions/action_service.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,13 @@ function makeActionManager(env) {
847847
* @param {ActionOptions} options
848848
*/
849849
async function _executeReportAction(action, options) {
850+
const handlers = registry.category("ir.actions.report handlers").getAll();
851+
for (const handler of handlers) {
852+
const result = await handler(action, options, env);
853+
if (result) {
854+
return result;
855+
}
856+
}
850857
if (action.report_type === "qweb-html") {
851858
return _executeReportClientAction(action, options);
852859
} else if (action.report_type === "qweb-pdf") {

addons/web/static/tests/webclient/actions/report_action_tests.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,41 @@ QUnit.module("ActionManager", (hooks) => {
269269
ui.bus.off("UNBLOCK", webClient);
270270
}
271271
);
272+
273+
QUnit.test("can use custom handlers for report actions", async function (assert) {
274+
assert.expect(8);
275+
mockDownload((options) => {
276+
assert.step(options.url);
277+
return Promise.resolve();
278+
});
279+
const mockRPC = async (route, args) => {
280+
assert.step((args && args.method) || route);
281+
if (route === "/report/check_wkhtmltopdf") {
282+
return "ok";
283+
}
284+
};
285+
const webClient = await createWebClient({ testConfig, mockRPC });
286+
let customHandlerCalled = false;
287+
registry.category("ir.actions.report handlers").add("custom_handler", async action => {
288+
if (action.id === 7 && !customHandlerCalled) {
289+
customHandlerCalled = true;
290+
assert.step("calling custom handler");
291+
return true;
292+
}
293+
assert.step("falling through to default handler");
294+
});
295+
await doAction(webClient, 7);
296+
assert.step("first doAction finished");
297+
await doAction(webClient, 7);
298+
299+
assert.verifySteps([
300+
"/web/webclient/load_menus",
301+
"/web/action/load",
302+
"calling custom handler",
303+
"first doAction finished",
304+
"falling through to default handler",
305+
"/report/check_wkhtmltopdf",
306+
"/report/download",
307+
]);
308+
});
272309
});

0 commit comments

Comments
 (0)