diff --git a/report_xml/__manifest__.py b/report_xml/__manifest__.py index 2e554a986..96c898c3d 100644 --- a/report_xml/__manifest__.py +++ b/report_xml/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). { "name": "XML Reports", - "version": "14.0.1.0.1", + "version": "15.0.1.0.0", "category": "Reporting", "website": "https://github.com/OCA/reporting-engine", "author": "Tecnativa, Odoo Community Association (OCA), Avoin.Systems", @@ -12,9 +12,13 @@ "summary": "Allow to generate XML reports", "depends": ["web"], "data": [ - "views/webclient_templates.xml", # add js handlers for action manager "views/ir_actions_report_view.xml", ], + "assets": { + "web.assets_backend": [ + "report_xml/static/src/js/report/action_manager_report.esm.js", + ], + }, "demo": [ "demo/report.xml", # register report in the system "demo/demo_report.xml", # report body definition diff --git a/report_xml/controllers/main.py b/report_xml/controllers/main.py index f8cc0905b..abaa4c767 100644 --- a/report_xml/controllers/main.py +++ b/report_xml/controllers/main.py @@ -42,7 +42,7 @@ class ReportController(report.ReportController): return super().report_routes(reportname, docids, converter, **data) @route() - def report_download(self, data, token, context=None): + def report_download(self, data, context=None): requestcontent = json.loads(data) url, report_type = requestcontent[0], requestcontent[1] if report_type == "qweb-xml": @@ -88,11 +88,10 @@ class ReportController(report.ReportController): response.headers.add( "Content-Disposition", content_disposition(filename) ) - response.set_cookie("fileToken", token) return response except Exception as e: se = serialize_exception(e) error = {"code": 200, "message": "Odoo Server Error", "data": se} return request.make_response(html_escape(json.dumps(error))) else: - return super().report_download(data, token, context) + return super().report_download(data, context) diff --git a/report_xml/hooks.py b/report_xml/hooks.py index 67a17a64c..c80a3c7a3 100644 --- a/report_xml/hooks.py +++ b/report_xml/hooks.py @@ -22,26 +22,25 @@ def post_init_hook(cr, registry): * registry(odoo.modules.registry.RegistryManager) - a mapping between model names and model classes. """ - with api.Environment.manage(): - env = api.Environment(cr, SUPERUSER_ID, {}) - report_domain = [ - ("report_name", "=", "report_xml.demo_report_xml_view") # report tech name - ] - demo_report = env["ir.actions.report"].search(report_domain, limit=1) - if demo_report: - dir_path = os.path.dirname(__file__) - xsd_file_relative_path = "demo/demo_report.xsd" - xsd_file_full_path = os.path.join(dir_path, xsd_file_relative_path) + env = api.Environment(cr, SUPERUSER_ID, {}) + report_domain = [ + ("report_name", "=", "report_xml.demo_report_xml_view") # report tech name + ] + demo_report = env["ir.actions.report"].search(report_domain, limit=1) + if demo_report: + dir_path = os.path.dirname(__file__) + xsd_file_relative_path = "demo/demo_report.xsd" + xsd_file_full_path = os.path.join(dir_path, xsd_file_relative_path) - with open(xsd_file_full_path, "r") as xsd: - # `xsd_schema` is binary fields with an attribute - # `attachment=True` so XSD Schema will be added as attachment - attach_vals = { - "name": "Demo Report.xsd", - "datas": xsd.read(), - "res_model": "ir.actions.report", - "res_id": demo_report.id, - "res_field": "xsd_schema", - "type": "binary", - } - env["ir.attachment"].create(attach_vals) + with open(xsd_file_full_path, "r") as xsd: + # `xsd_schema` is binary fields with an attribute + # `attachment=True` so XSD Schema will be added as attachment + attach_vals = { + "name": "Demo Report.xsd", + "datas": xsd.read(), + "res_model": "ir.actions.report", + "res_id": demo_report.id, + "res_field": "xsd_schema", + "type": "binary", + } + env["ir.attachment"].create(attach_vals) diff --git a/report_xml/static/src/js/report/action_manager_report.esm.js b/report_xml/static/src/js/report/action_manager_report.esm.js new file mode 100644 index 000000000..3bfe488af --- /dev/null +++ b/report_xml/static/src/js/report/action_manager_report.esm.js @@ -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); diff --git a/report_xml/static/src/js/report/action_manager_report.js b/report_xml/static/src/js/report/action_manager_report.js deleted file mode 100644 index 76324b9a2..000000000 --- a/report_xml/static/src/js/report/action_manager_report.js +++ /dev/null @@ -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; - }, - }); -}); diff --git a/report_xml/views/webclient_templates.xml b/report_xml/views/webclient_templates.xml deleted file mode 100644 index 417786ac1..000000000 --- a/report_xml/views/webclient_templates.xml +++ /dev/null @@ -1,11 +0,0 @@ - - -