[MIG] report_xml: Migration to 12.0

This commit is contained in:
ernesto
2019-06-10 13:29:22 -04:00
committed by Enric Tobella
parent 6c584c5e3b
commit 886ac9b71c
22 changed files with 727 additions and 152 deletions

View File

@@ -1,14 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
import logging
from odoo import api, fields, models
from lxml import etree
_logger = logging.getLogger(__name__)
class ReportAction(models.Model):
_inherit = "ir.actions.report"
@@ -16,23 +11,15 @@ class ReportAction(models.Model):
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
@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_qweb_xml(self, docids, data):
result = self.render_qweb_html(docids, data=data)
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[0], 'UTF-8').lstrip('\n').lstrip().encode('UTF-8')
str(result, 'UTF-8').lstrip('\n').lstrip().encode('UTF-8')
),
encoding='UTF-8',
xml_declaration=True,