[MIG] report_py3o: Migration to 15.0

pull/695/head
Tran Thanh Phuc 2022-05-15 22:18:31 +07:00 committed by Alexis de Lattre
parent fd240b6850
commit aa228f0d89
11 changed files with 83 additions and 74 deletions

View File

@ -14,13 +14,13 @@ Py3o Report Engine
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_py3o :target: https://github.com/OCA/reporting-engine/tree/15.0/report_py3o
:alt: OCA/reporting-engine :alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_py3o :target: https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_py3o
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/143/14.0 :target: https://runbot.odoo-community.org/runbot/143/15.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -203,7 +203,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -225,6 +225,7 @@ Contributors
* Guewen Baconnier <guewen.baconnier@camptocamp.com> * Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Omar Castiñeira <omar@comunitea.com> * Omar Castiñeira <omar@comunitea.com>
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Phuc Tran Thanh <phuc@trobz.com>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -239,6 +240,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_py3o>`_ project on GitHub. This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/15.0/report_py3o>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -4,19 +4,26 @@
"name": "Py3o Report Engine", "name": "Py3o Report Engine",
"summary": "Reporting engine based on Libreoffice (ODT -> ODT, " "summary": "Reporting engine based on Libreoffice (ODT -> ODT, "
"ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)", "ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)",
"version": "14.0.1.0.0", "version": "15.0.1.0.0",
"category": "Reporting", "category": "Reporting",
"license": "AGPL-3", "license": "AGPL-3",
"author": "XCG Consulting," "ACSONE SA/NV," "Odoo Community Association (OCA)", "author": "XCG Consulting," "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine", "website": "https://github.com/OCA/reporting-engine",
"depends": ["web"], "depends": ["web"],
"external_dependencies": {"python": ["py3o.template", "py3o.formats", "PyPDF2"]}, "external_dependencies": {
"python": ["py3o.template", "py3o.formats", "PyPDF2"],
"deb": ["libreoffice"],
},
"assets": {
"web.assets_backend": [
"report_py3o/static/src/js/py3oactionservice.esm.js",
],
},
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",
"views/menu.xml", "views/menu.xml",
"views/py3o_template.xml", "views/py3o_template.xml",
"views/ir_actions_report.xml", "views/ir_actions_report.xml",
"views/report_py3o.xml",
"demo/report_py3o.xml", "demo/report_py3o.xml",
], ],
"installable": True, "installable": True,

View File

@ -38,7 +38,7 @@ class ReportController(main.ReportController):
ir_action = request.env["ir.actions.report"] ir_action = request.env["ir.actions.report"]
action_py3o_report = ir_action.get_from_report_name( action_py3o_report = ir_action.get_from_report_name(
reportname, "py3o" reportname, "py3o"
).with_context(context) ).with_context(**context)
if not action_py3o_report: if not action_py3o_report:
raise exceptions.HTTPException( raise exceptions.HTTPException(
description="Py3o action report not found for report_name " description="Py3o action report not found for report_name "
@ -57,7 +57,7 @@ class ReportController(main.ReportController):
return request.make_response(res, headers=http_headers) return request.make_response(res, headers=http_headers)
@route() @route()
def report_download(self, data, token): def report_download(self, data, context=None):
"""This function is used by 'qwebactionmanager.js' in order to trigger """This function is used by 'qwebactionmanager.js' in order to trigger
the download of a py3o/controller report. the download of a py3o/controller report.
@ -68,7 +68,7 @@ class ReportController(main.ReportController):
requestcontent = json.loads(data) requestcontent = json.loads(data)
url, report_type = requestcontent[0], requestcontent[1] url, report_type = requestcontent[0], requestcontent[1]
if "py3o" not in report_type: if "py3o" not in report_type:
return super(ReportController, self).report_download(data, token) return super(ReportController, self).report_download(data, context)
try: try:
reportname = url.split("/report/py3o/")[1].split("?")[0] reportname = url.split("/report/py3o/")[1].split("?")[0]
docids = None docids = None
@ -87,7 +87,7 @@ class ReportController(main.ReportController):
response = self.report_routes( response = self.report_routes(
reportname, converter="py3o", **dict(data) reportname, converter="py3o", **dict(data)
) )
response.set_cookie("fileToken", token) response.set_cookie("fileToken", context)
return response return response
except Exception as e: except Exception as e:
se = _serialize_exception(e) se = _serialize_exception(e)

View File

@ -58,9 +58,7 @@ class IrActionsReport(models.Model):
) )
is_py3o_native_format = fields.Boolean(compute="_compute_is_py3o_native_format") is_py3o_native_format = fields.Boolean(compute="_compute_is_py3o_native_format")
py3o_template_id = fields.Many2one("py3o.template", "Template") py3o_template_id = fields.Many2one("py3o.template", "Template")
module = fields.Char( module = fields.Char(help="The implementer module that provides this report")
"Module", help="The implementer module that provides this report"
)
py3o_template_fallback = fields.Char( py3o_template_fallback = fields.Char(
"Fallback", "Fallback",
size=128, size=128,

View File

@ -4,3 +4,4 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com> * Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Omar Castiñeira <omar@comunitea.com> * Omar Castiñeira <omar@comunitea.com>
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Phuc Tran Thanh <phuc@trobz.com>

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Py3o Report Engine</title> <title>Py3o Report Engine</title>
<style type="text/css"> <style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/14.0/report_py3o"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_py3o"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_py3o"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_py3o"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>The py3o reporting engine is a reporting engine for Odoo based on <a class="reference external" href="http://www.libreoffice.org/">Libreoffice</a>:</p> <p>The py3o reporting engine is a reporting engine for Odoo based on <a class="reference external" href="http://www.libreoffice.org/">Libreoffice</a>:</p>
<ul class="simple"> <ul class="simple">
<li>the report is created with Libreoffice (ODT or ODS),</li> <li>the report is created with Libreoffice (ODT or ODS),</li>
@ -546,7 +546,7 @@ root_tmpl_path=/odoo/templates/py3o
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/reporting-engine/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/reporting-engine/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -567,6 +567,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li> <li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li>
<li>Omar Castiñeira &lt;<a class="reference external" href="mailto:omar&#64;comunitea.com">omar&#64;comunitea.com</a>&gt;</li> <li>Omar Castiñeira &lt;<a class="reference external" href="mailto:omar&#64;comunitea.com">omar&#64;comunitea.com</a>&gt;</li>
<li>Holger Brunn &lt;<a class="reference external" href="mailto:hbrunn&#64;therp.nl">hbrunn&#64;therp.nl</a>&gt;</li> <li>Holger Brunn &lt;<a class="reference external" href="mailto:hbrunn&#64;therp.nl">hbrunn&#64;therp.nl</a>&gt;</li>
<li>Phuc Tran Thanh &lt;<a class="reference external" href="mailto:phuc&#64;trobz.com">phuc&#64;trobz.com</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -576,7 +577,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/14.0/report_py3o">OCA/reporting-engine</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_py3o">OCA/reporting-engine</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -1,42 +0,0 @@
/* Copyright 2017-2018 ACSONE SA/NV
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("report_py3o.report", function (require) {
"use strict";
var ActionManager = require("web.ActionManager");
ActionManager.include({
_executeReportAction: function (action, options) {
// Py3o reports
if ("report_type" in action && action.report_type === "py3o") {
return this._triggerDownload(action, options, "py3o");
}
return this._super.apply(this, arguments);
},
_makeReportUrls: function (action) {
var reportUrls = this._super.apply(this, arguments);
reportUrls.py3o = "/report/py3o/" + action.report_name;
// We may have to build a query string with `action.data`. It's the place
// were report's using a wizard to customize the output traditionally put
// their options.
if (
_.isUndefined(action.data) ||
_.isNull(action.data) ||
(_.isObject(action.data) && _.isEmpty(action.data))
) {
if (action.context.active_ids) {
var activeIDsPath = "/" + action.context.active_ids.join(",");
reportUrls.py3o += activeIDsPath;
}
} else {
var serializedOptionsPath =
"?options=" + encodeURIComponent(JSON.stringify(action.data));
serializedOptionsPath +=
"&context=" + encodeURIComponent(JSON.stringify(action.context));
reportUrls.py3o += serializedOptionsPath;
}
return reportUrls;
},
});
});

View 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("py3o_handler", async function (action, options, env) {
if (action.report_type === "py3o") {
let url = `/report/py3o/${action.report_name}`;
const actionContext = action.context || {};
if (
_.isUndefined(action.data) ||
_.isNull(action.data) ||
(_.isObject(action.data) && _.isEmpty(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)
if (actionContext.active_ids) {
var activeIDsPath = "/" + actionContext.active_ids.join(",");
url += activeIDsPath;
}
} else {
var serializedOptionsPath =
"?options=" + encodeURIComponent(JSON.stringify(action.data));
serializedOptionsPath +=
"&context=" + encodeURIComponent(JSON.stringify(actionContext));
url += serializedOptionsPath;
}
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);
});

View File

@ -165,7 +165,7 @@ class TestReportPy3o(TransactionCase):
with temporary_copy(flbk_filename) as tmp_filename: with temporary_copy(flbk_filename) as tmp_filename:
self.report.py3o_template_fallback = tmp_filename self.report.py3o_template_fallback = tmp_filename
tools.config.misc["report_py3o"] = { tools.config.misc["report_py3o"] = {
"root_tmpl_path": os.path.dirname(tmp_filename) "root_tmpl_path": os.path.realpath(os.path.dirname(tmp_filename))
} }
res = self.report._render(self.env.user.ids) res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)

View File

@ -34,7 +34,7 @@
<field name="name">py3o.template.configuration.tree.view</field> <field name="name">py3o.template.configuration.tree.view</field>
<field name="model">py3o.template</field> <field name="model">py3o.template</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Py3o Templates"> <tree>
<field name="name" /> <field name="name" />
<field name="filetype" /> <field name="filetype" />
</tree> </tree>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend" name="report assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/report_py3o/static/src/js/py3oactionmanager.js"
/>
</xpath>
</template>
</odoo>