mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_csv: Migration to 15.0
This commit is contained in:
54
report_csv/static/src/js/report/qwebactionmanager.esm.js
Normal file
54
report_csv/static/src/js/report/qwebactionmanager.esm.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {download} from "@web/core/network/download";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
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(env.services.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(env.services.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);
|
||||
});
|
||||
@@ -1,98 +0,0 @@
|
||||
// © 2019 Creu Blanca
|
||||
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
odoo.define("report_csv.report", function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
var ActionManager = require("web.ActionManager");
|
||||
var framework = require("web.framework");
|
||||
var session = require("web.session");
|
||||
var _t = core._t;
|
||||
|
||||
ActionManager.include({
|
||||
_downloadReportCSV: function (url, actions) {
|
||||
var self = this;
|
||||
framework.blockUI();
|
||||
var type = "csv";
|
||||
var cloned_action = _.clone(actions);
|
||||
var report_url = url;
|
||||
|
||||
if (
|
||||
_.isUndefined(cloned_action.data) ||
|
||||
_.isNull(cloned_action.data) ||
|
||||
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data))
|
||||
) {
|
||||
if (cloned_action.context.active_ids) {
|
||||
report_url += "/" + cloned_action.context.active_ids.join(",");
|
||||
}
|
||||
} else {
|
||||
report_url +=
|
||||
"?options=" +
|
||||
encodeURIComponent(JSON.stringify(cloned_action.data));
|
||||
report_url +=
|
||||
"&context=" +
|
||||
encodeURIComponent(JSON.stringify(cloned_action.context));
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var blocked = !session.get_file({
|
||||
url: report_url,
|
||||
data: {
|
||||
data: JSON.stringify([report_url, type]),
|
||||
},
|
||||
success: resolve,
|
||||
error: (error) => {
|
||||
self.call("crash_manager", "rpc_error", error);
|
||||
reject();
|
||||
},
|
||||
complete: framework.unblockUI,
|
||||
});
|
||||
if (blocked) {
|
||||
// AAB: this check should be done in get_file service directly,
|
||||
// should not be the concern of the caller (and that way, get_file
|
||||
// could return a deferred)
|
||||
var message = _t(
|
||||
"A popup window with your report was blocked. You " +
|
||||
"may need to change your browser settings to allow " +
|
||||
"popup windows for this page."
|
||||
);
|
||||
this.do_warn(_t("Warning"), message, true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_triggerDownload: function (action, options, type) {
|
||||
var self = this;
|
||||
var reportUrls = this._makeReportUrls(action);
|
||||
if (type === "csv") {
|
||||
return this._downloadReportCSV(reportUrls[type], action).then(
|
||||
function () {
|
||||
if (action.close_on_report_download) {
|
||||
var closeAction = {type: "ir.actions.act_window_close"};
|
||||
return self.doAction(
|
||||
closeAction,
|
||||
_.pick(options, "on_close")
|
||||
);
|
||||
}
|
||||
return options.on_close();
|
||||
}
|
||||
);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
_makeReportUrls: function (action) {
|
||||
var reportUrls = this._super.apply(this, arguments);
|
||||
reportUrls.csv = "/report/csv/" + action.report_name;
|
||||
return reportUrls;
|
||||
},
|
||||
|
||||
_executeReportAction: function (action, options) {
|
||||
var self = this;
|
||||
if (action.report_type === "csv") {
|
||||
return self._triggerDownload(action, options, "csv");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user