[IMP] web: add support for custom handlers for ir.actions.report

closes odoo-dev/odoo#873

Related: odoo-dev/enterprise#144
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Samuel Degueldre
2021-06-18 21:31:29 +02:00
committed by Aaron Bohy
parent ba9fd57592
commit 8daff40725
2 changed files with 44 additions and 0 deletions
@@ -849,6 +849,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") {
@@ -269,4 +269,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",
]);
});
});