[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 servicepull/550/head
parent
6b32b822f6
commit
e5eff57f86
|
@ -2,7 +2,7 @@
|
||||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
{
|
{
|
||||||
"name": "XML Reports",
|
"name": "XML Reports",
|
||||||
"version": "14.0.1.0.1",
|
"version": "15.0.1.0.0",
|
||||||
"category": "Reporting",
|
"category": "Reporting",
|
||||||
"website": "https://github.com/OCA/reporting-engine",
|
"website": "https://github.com/OCA/reporting-engine",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA), Avoin.Systems",
|
"author": "Tecnativa, Odoo Community Association (OCA), Avoin.Systems",
|
||||||
|
@ -12,9 +12,13 @@
|
||||||
"summary": "Allow to generate XML reports",
|
"summary": "Allow to generate XML reports",
|
||||||
"depends": ["web"],
|
"depends": ["web"],
|
||||||
"data": [
|
"data": [
|
||||||
"views/webclient_templates.xml", # add js handlers for action manager
|
|
||||||
"views/ir_actions_report_view.xml",
|
"views/ir_actions_report_view.xml",
|
||||||
],
|
],
|
||||||
|
"assets": {
|
||||||
|
"web.assets_backend": [
|
||||||
|
"report_xml/static/src/js/report/action_manager_report.esm.js",
|
||||||
|
],
|
||||||
|
},
|
||||||
"demo": [
|
"demo": [
|
||||||
"demo/report.xml", # register report in the system
|
"demo/report.xml", # register report in the system
|
||||||
"demo/demo_report.xml", # report body definition
|
"demo/demo_report.xml", # report body definition
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ReportController(report.ReportController):
|
||||||
return super().report_routes(reportname, docids, converter, **data)
|
return super().report_routes(reportname, docids, converter, **data)
|
||||||
|
|
||||||
@route()
|
@route()
|
||||||
def report_download(self, data, token, context=None):
|
def report_download(self, data, context=None):
|
||||||
requestcontent = json.loads(data)
|
requestcontent = json.loads(data)
|
||||||
url, report_type = requestcontent[0], requestcontent[1]
|
url, report_type = requestcontent[0], requestcontent[1]
|
||||||
if report_type == "qweb-xml":
|
if report_type == "qweb-xml":
|
||||||
|
@ -88,11 +88,10 @@ class ReportController(report.ReportController):
|
||||||
response.headers.add(
|
response.headers.add(
|
||||||
"Content-Disposition", content_disposition(filename)
|
"Content-Disposition", content_disposition(filename)
|
||||||
)
|
)
|
||||||
response.set_cookie("fileToken", token)
|
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
se = serialize_exception(e)
|
se = serialize_exception(e)
|
||||||
error = {"code": 200, "message": "Odoo Server Error", "data": se}
|
error = {"code": 200, "message": "Odoo Server Error", "data": se}
|
||||||
return request.make_response(html_escape(json.dumps(error)))
|
return request.make_response(html_escape(json.dumps(error)))
|
||||||
else:
|
else:
|
||||||
return super().report_download(data, token, context)
|
return super().report_download(data, context)
|
||||||
|
|
|
@ -22,26 +22,25 @@ def post_init_hook(cr, registry):
|
||||||
* registry(odoo.modules.registry.RegistryManager) - a mapping between
|
* registry(odoo.modules.registry.RegistryManager) - a mapping between
|
||||||
model names and model classes.
|
model names and model classes.
|
||||||
"""
|
"""
|
||||||
with api.Environment.manage():
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
report_domain = [
|
||||||
report_domain = [
|
("report_name", "=", "report_xml.demo_report_xml_view") # report tech name
|
||||||
("report_name", "=", "report_xml.demo_report_xml_view") # report tech name
|
]
|
||||||
]
|
demo_report = env["ir.actions.report"].search(report_domain, limit=1)
|
||||||
demo_report = env["ir.actions.report"].search(report_domain, limit=1)
|
if demo_report:
|
||||||
if demo_report:
|
dir_path = os.path.dirname(__file__)
|
||||||
dir_path = os.path.dirname(__file__)
|
xsd_file_relative_path = "demo/demo_report.xsd"
|
||||||
xsd_file_relative_path = "demo/demo_report.xsd"
|
xsd_file_full_path = os.path.join(dir_path, xsd_file_relative_path)
|
||||||
xsd_file_full_path = os.path.join(dir_path, xsd_file_relative_path)
|
|
||||||
|
|
||||||
with open(xsd_file_full_path, "r") as xsd:
|
with open(xsd_file_full_path, "r") as xsd:
|
||||||
# `xsd_schema` is binary fields with an attribute
|
# `xsd_schema` is binary fields with an attribute
|
||||||
# `attachment=True` so XSD Schema will be added as attachment
|
# `attachment=True` so XSD Schema will be added as attachment
|
||||||
attach_vals = {
|
attach_vals = {
|
||||||
"name": "Demo Report.xsd",
|
"name": "Demo Report.xsd",
|
||||||
"datas": xsd.read(),
|
"datas": xsd.read(),
|
||||||
"res_model": "ir.actions.report",
|
"res_model": "ir.actions.report",
|
||||||
"res_id": demo_report.id,
|
"res_id": demo_report.id,
|
||||||
"res_field": "xsd_schema",
|
"res_field": "xsd_schema",
|
||||||
"type": "binary",
|
"type": "binary",
|
||||||
}
|
}
|
||||||
env["ir.attachment"].create(attach_vals)
|
env["ir.attachment"].create(attach_vals)
|
||||||
|
|
|
@ -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);
|
|
@ -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;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<odoo>
|
|
||||||
<template id="report_xml.assets_backend" inherit_id="web.assets_backend">
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<script
|
|
||||||
type="text/javascript"
|
|
||||||
src="/report_xml/static/src/js/report/action_manager_report.js"
|
|
||||||
/>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</odoo>
|
|
Loading…
Reference in New Issue