mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_xml: Migration to 14.0
This commit is contained in:
committed by
Enric Tobella
parent
09d1d54ee6
commit
98262b1445
@@ -120,6 +120,7 @@ Contributors
|
|||||||
* Jairo Llopis
|
* Jairo Llopis
|
||||||
* `Avoin.Systems <https://avoin.systems/>`_:
|
* `Avoin.Systems <https://avoin.systems/>`_:
|
||||||
* Tatiana Deribina
|
* Tatiana Deribina
|
||||||
|
* Iván Antón <ozono@ozonomultimedia.com>
|
||||||
|
|
||||||
Other credits
|
Other credits
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -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": "13.0.1.0.0",
|
"version": "14.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",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
|
|
||||||
from werkzeug.urls import url_decode
|
from werkzeug.urls import url_decode
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ class ReportController(report.ReportController):
|
|||||||
del data["context"]["lang"]
|
del data["context"]["lang"]
|
||||||
context.update(data["context"])
|
context.update(data["context"])
|
||||||
|
|
||||||
xml = report.with_context(context).render_qweb_xml(docids, data=data)[0]
|
xml = report.with_context(context)._render_qweb_xml(docids, data=data)[0]
|
||||||
xmlhttpheaders = [
|
xmlhttpheaders = [
|
||||||
("Content-Type", "text/xml"),
|
("Content-Type", "text/xml"),
|
||||||
("Content-Length", len(xml)),
|
("Content-Length", len(xml)),
|
||||||
@@ -75,7 +74,7 @@ class ReportController(report.ReportController):
|
|||||||
records = request.env[report.model].browse(ids)
|
records = request.env[report.model].browse(ids)
|
||||||
if report.print_report_name and not len(records) > 1:
|
if report.print_report_name and not len(records) > 1:
|
||||||
report_name = safe_eval(
|
report_name = safe_eval(
|
||||||
report.print_report_name, {"object": records, "time": time}
|
report.print_report_name, {"object": records}
|
||||||
)
|
)
|
||||||
filename = "{}.xml".format(report_name)
|
filename = "{}.xml".format(report_name)
|
||||||
response.headers.add(
|
response.headers.add(
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<report
|
<record id="demo_xml_report" model="ir.actions.report">
|
||||||
id="demo_xml_report"
|
<field name="name">Demo xml report</field>
|
||||||
name="report_xml.demo_report_xml_view"
|
<field name="model">res.company</field>
|
||||||
string="Demo xml report"
|
<field name="report_type">qweb-xml</field>
|
||||||
report_type="qweb-xml"
|
<field name="report_name">report_xml.demo_report_xml_view</field>
|
||||||
print_report_name="'Demo xml report'"
|
<field name="report_file">res_company</field>
|
||||||
model="res.company"
|
|
||||||
/>
|
|
||||||
<!--
|
<!--
|
||||||
In case of demo data next definition will not work. So it just example
|
In case of demo data next definition will not work. So it just example
|
||||||
how it should look. If report is a part of demo data you will need
|
how it should look. If report is a part of demo data you will need
|
||||||
add file to report instance via `post_install_hook`
|
add file to report instance via `post_install_hook`
|
||||||
-->
|
-->
|
||||||
<record id="demo_xml_report" model="ir.actions.report">
|
|
||||||
<field name="xsd_schema" type="base64" file="report_xml/demo/demo_report.xsd" />
|
<field name="xsd_schema" type="base64" file="report_xml/demo/demo_report.xsd" />
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ from odoo import fields, models
|
|||||||
class IrActionsReport(models.Model):
|
class IrActionsReport(models.Model):
|
||||||
_inherit = "ir.actions.report"
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
report_type = fields.Selection(
|
||||||
|
selection_add=[("qweb-xml", "XML")], ondelete={"qweb-xml": "set default"}
|
||||||
|
)
|
||||||
xsd_schema = fields.Binary(
|
xsd_schema = fields.Binary(
|
||||||
string="XSD Validation Schema",
|
string="XSD Validation Schema",
|
||||||
attachment=True,
|
attachment=True,
|
||||||
@@ -34,7 +36,7 @@ class IrActionsReport(models.Model):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_qweb_xml(self, docids, data=None):
|
def _render_qweb_xml(self, docids, data=None):
|
||||||
"""
|
"""
|
||||||
Call `generate_report` method of report abstract class
|
Call `generate_report` method of report abstract class
|
||||||
`report.<report technical name>` or of standard class for XML report
|
`report.<report technical name>` or of standard class for XML report
|
||||||
|
|||||||
@@ -3,3 +3,4 @@
|
|||||||
* Jairo Llopis
|
* Jairo Llopis
|
||||||
* `Avoin.Systems <https://avoin.systems/>`_:
|
* `Avoin.Systems <https://avoin.systems/>`_:
|
||||||
* Tatiana Deribina
|
* Tatiana Deribina
|
||||||
|
* Iván Antón <ozono@ozonomultimedia.com>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class ReportXmlAbstract(models.AbstractModel):
|
|||||||
data = ir_report._get_rendering_context(docids, data)
|
data = ir_report._get_rendering_context(docids, data)
|
||||||
|
|
||||||
# render template
|
# render template
|
||||||
result_bin = ir_report.render_template(ir_report.report_name, data)
|
result_bin = ir_report._render_template(ir_report.report_name, data)
|
||||||
|
|
||||||
# prettify result content
|
# prettify result content
|
||||||
# normalize indents
|
# normalize indents
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class TestXmlReport(common.TransactionCase):
|
|||||||
report = report_object._get_report_from_name(report_name)
|
report = report_object._get_report_from_name(report_name)
|
||||||
docs = self.env["res.company"].search([], limit=1)
|
docs = self.env["res.company"].search([], limit=1)
|
||||||
self.assertEqual(report.report_type, "qweb-xml")
|
self.assertEqual(report.report_type, "qweb-xml")
|
||||||
result_report = report.render(docs.ids, {})
|
result_report = report._render(docs.ids, {})
|
||||||
result_tree = etree.fromstring(result_report[0])
|
result_tree = etree.fromstring(result_report[0])
|
||||||
el = result_tree.xpath("/root/user/name")
|
el = result_tree.xpath("/root/user/name")
|
||||||
self.assertEqual(el[0].text, docs.ensure_one().name)
|
self.assertEqual(el[0].text, docs.ensure_one().name)
|
||||||
|
|||||||
Reference in New Issue
Block a user