Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
51
report_csv/static/src/js/report/qwebactionmanager.esm.js
Normal file
51
report_csv/static/src/js/report/qwebactionmanager.esm.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import {download} from "@web/core/network/download";
|
||||
import {registry} from "@web/core/registry";
|
||||
import {user} from "@web/core/user";
|
||||
|
||||
registry
|
||||
.category("ir.actions.report handlers")
|
||||
.add("csv_handler", async function (action, options, env) {
|
||||
if (action.report_type === "csv") {
|
||||
const type = action.report_type;
|
||||
let url = `/report/${type}/${action.report_name}`;
|
||||
const actionContext = action.context || {};
|
||||
if (action.data && JSON.stringify(action.data) !== "{}") {
|
||||
// Build a query string with `action.data` (it's the place where reports
|
||||
// using a wizard to customize the output traditionally put their options)
|
||||
const action_options = encodeURIComponent(JSON.stringify(action.data));
|
||||
const context = encodeURIComponent(JSON.stringify(actionContext));
|
||||
url += `?options=${action_options}&context=${context}`;
|
||||
} else {
|
||||
if (actionContext.active_ids) {
|
||||
url += `/${actionContext.active_ids.join(",")}`;
|
||||
}
|
||||
if (type === "csv") {
|
||||
const context = encodeURIComponent(JSON.stringify(user.context));
|
||||
url += `?context=${context}`;
|
||||
}
|
||||
}
|
||||
env.services.ui.block();
|
||||
try {
|
||||
await download({
|
||||
url: "/report/download",
|
||||
data: {
|
||||
data: JSON.stringify([url, action.report_type]),
|
||||
context: JSON.stringify(user.context),
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
env.services.ui.unblock();
|
||||
}
|
||||
const onClose = options.onClose;
|
||||
if (action.close_on_report_download) {
|
||||
return env.services.action.doAction(
|
||||
{type: "ir.actions.act_window_close"},
|
||||
{onClose}
|
||||
);
|
||||
} else if (onClose) {
|
||||
onClose();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
return Promise.resolve(false);
|
||||
});
|
||||
Reference in New Issue
Block a user