[MIG] report_xml: migrate 14 -> 15

* No longer need `with Environment.manage()`
* Assets are registered in manifest file now
* ReportController endpoints no longer take a `token` parameter
* The frontend ActionManager has been rewritten as an Owl service
This commit is contained in:
Atte Isopuro
2021-11-26 14:28:12 +02:00
committed by Santeri Valjakka
parent 6b32b822f6
commit e5eff57f86
6 changed files with 95 additions and 57 deletions

View File

@@ -0,0 +1,66 @@
/** @odoo-module **/
import {download} from "@web/core/network/download";
import {registry} from "@web/core/registry";
async function xmlReportHandler(action, options, env) {
if (action.report_type === "qweb-xml") {
// Workaround/hack: Odoo does not expose the _triggerDownload method on
// the service, so we have no way to access it from here. We therefore
// copy the code; as it is private, it doesn't really give any
// stability guarantees anyway
// If _triggerDownload were publically available on the service, the
// code below could be replaced by
// env.services.action._triggerDownload(action, options, "xml");
const type = "xml";
// COPY actionManager._getReportUrl
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 options_ = encodeURIComponent(JSON.stringify(action.data));
const context_ = encodeURIComponent(JSON.stringify(actionContext));
url_ += `?options=${options_}&context=${context_}`;
} else {
if (actionContext.active_ids) {
url_ += `/${actionContext.active_ids.join(",")}`;
}
if (type === "xml") {
const context = encodeURIComponent(
JSON.stringify(env.services.user.context)
);
url_ += `?context=${context}`;
}
}
// COPY actionManager._triggerDownload
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();
}
// DIFF: need to inform success to the original method. Otherwise it
// will think our hook function did nothing and run the original
// method.
return Promise.resolve(true);
}
}
registry.category("ir.actions.report handlers").add("xml_handler", xmlReportHandler);

View File

@@ -1,19 +0,0 @@
odoo.define("report_xml.ReportActionManager", function (require) {
"use strict";
var ActionManager = require("web.ActionManager");
ActionManager.include({
_executeReportAction: function (action, options) {
if (action.report_type === "qweb-xml") {
return this._triggerDownload(action, options, "xml");
}
return this._super(action, options);
},
_makeReportUrls: function (action) {
var reportUrls = this._super(action);
reportUrls.xml = reportUrls.text.replace("/report/text/", "/report/xml/");
return reportUrls;
},
});
});