mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_xml: Migration to 11.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
|
||||
import logging
|
||||
|
||||
@@ -11,39 +11,30 @@ _logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ReportAction(models.Model):
|
||||
_inherit = "ir.actions.report.xml"
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
||||
|
||||
def _lookup_report(self, name):
|
||||
"""Enable ``qweb-xml`` report lookup."""
|
||||
try:
|
||||
return super(ReportAction, self)._lookup_report(name)
|
||||
except Exception as ex:
|
||||
# Somebody thought it was a good idea to use standard exceptions
|
||||
if "qweb-xml" not in ex.message:
|
||||
raise ex
|
||||
else:
|
||||
self._cr.execute(
|
||||
"SELECT * FROM ir_act_report_xml WHERE report_name=%s",
|
||||
(name,))
|
||||
return self._cr.dictfetchone()["report_name"]
|
||||
@api.model
|
||||
def _get_report_from_name(self, report_name):
|
||||
res = super(ReportAction, self)._get_report_from_name(report_name)
|
||||
if res:
|
||||
return res
|
||||
report_obj = self.env['ir.actions.report']
|
||||
qwebtypes = ['qweb-xml']
|
||||
conditions = [('report_type', 'in', qwebtypes),
|
||||
('report_name', '=', report_name)]
|
||||
context = self.env['res.users'].context_get()
|
||||
return report_obj.with_context(context).search(conditions, limit=1)
|
||||
|
||||
@api.model
|
||||
def render_report(self, res_ids, name, data):
|
||||
"""Special handling for ``qweb-xml`` reports."""
|
||||
xml_report = self.search([('report_name', '=', name),
|
||||
('report_type', '=', 'qweb-xml')], limit=1)
|
||||
if xml_report:
|
||||
xml_report = xml_report.ensure_one()
|
||||
result = self.env["report"].get_html(res_ids,
|
||||
xml_report.report_name,
|
||||
data=data)
|
||||
return (
|
||||
etree.tostring(
|
||||
etree.fromstring(result.strip()),
|
||||
encoding='UTF-8', xml_declaration=True, pretty_print=True
|
||||
), "xml")
|
||||
else:
|
||||
return super(ReportAction, self).render_report(
|
||||
res_ids, name, data)
|
||||
def render_qweb_xml(self, docids, data):
|
||||
result = self.render_qweb_html(docids, data=data)
|
||||
return etree.tostring(
|
||||
etree.fromstring(
|
||||
str(result[0], '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