mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG][13.0] report_xml: Migration to 13.0
This commit is contained in:
committed by
Enric Tobella
parent
e2869482c9
commit
9df5049644
@@ -1,3 +1,3 @@
|
||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
||||
from . import report_action
|
||||
from . import ir_actions_report
|
||||
|
||||
62
report_xml/models/ir_actions_report.py
Normal file
62
report_xml/models/ir_actions_report.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
||||
xsd_schema = fields.Binary(
|
||||
string="XSD Validation Schema",
|
||||
attachment=True,
|
||||
help=(
|
||||
"File with XSD Schema for checking content of result report. "
|
||||
"Can be empty if validation is not required."
|
||||
),
|
||||
)
|
||||
xml_encoding = fields.Selection(
|
||||
selection=[
|
||||
("UTF-8", "UTF-8") # will be used as default even if nothing is selected
|
||||
],
|
||||
string="XML Encoding",
|
||||
help=(
|
||||
"Encoding for XML reports. If nothing is selected, "
|
||||
"then UTF-8 will be applied."
|
||||
),
|
||||
)
|
||||
xml_declaration = fields.Boolean(
|
||||
string="XML Declaration",
|
||||
help=(
|
||||
"""Add `<?xml encoding="..." version="..."?>` at the start """
|
||||
"""of final report file."""
|
||||
),
|
||||
)
|
||||
|
||||
def render_qweb_xml(self, docids, data=None):
|
||||
"""
|
||||
Call `generate_report` method of report abstract class
|
||||
`report.<report technical name>` or of standard class for XML report
|
||||
rendering - `report.report_xml.abstract`
|
||||
|
||||
Args:
|
||||
* docids(list) - IDs of instances for those report will be generated
|
||||
* data(dict, None) - variables for report rendering
|
||||
|
||||
Returns:
|
||||
* str - result content of report
|
||||
* str - type of result content
|
||||
"""
|
||||
report_model_name = "report.{}".format(self.report_name)
|
||||
|
||||
report_model = self.env.get(report_model_name)
|
||||
if report_model is None:
|
||||
report_model = self.env["report.report_xml.abstract"]
|
||||
|
||||
content, ttype = report_model.generate_report(
|
||||
ir_report=self, # will be used to get settings of report
|
||||
docids=docids,
|
||||
data=data,
|
||||
)
|
||||
return content, ttype
|
||||
@@ -1,31 +0,0 @@
|
||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ReportAction(models.Model):
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
||||
|
||||
@api.model
|
||||
def render_qweb_xml(self, docids, data=None):
|
||||
if not data:
|
||||
data = {}
|
||||
data.setdefault("report_type", "text")
|
||||
data = self._get_rendering_context(docids, data)
|
||||
result = self.render_template(self.report_name, data)
|
||||
return (
|
||||
etree.tostring(
|
||||
etree.fromstring(
|
||||
str(result, "UTF-8").lstrip("\n").lstrip().encode("UTF-8")
|
||||
),
|
||||
encoding="UTF-8",
|
||||
xml_declaration=True,
|
||||
pretty_print=True,
|
||||
),
|
||||
"xml",
|
||||
)
|
||||
Reference in New Issue
Block a user