OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  3. # License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
  4. import logging
  5. from odoo import api, fields, models
  6. from lxml import etree
  7. _logger = logging.getLogger(__name__)
  8. class ReportAction(models.Model):
  9. _inherit = "ir.actions.report"
  10. report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
  11. @api.model
  12. def _get_report_from_name(self, report_name):
  13. res = super(ReportAction, self)._get_report_from_name(report_name)
  14. if res:
  15. return res
  16. report_obj = self.env['ir.actions.report']
  17. qwebtypes = ['qweb-xml']
  18. conditions = [('report_type', 'in', qwebtypes),
  19. ('report_name', '=', report_name)]
  20. context = self.env['res.users'].context_get()
  21. return report_obj.with_context(context).search(conditions, limit=1)
  22. @api.model
  23. def render_qweb_xml(self, docids, data):
  24. result = self.render_qweb_html(docids, data=data)
  25. return etree.tostring(
  26. etree.fromstring(
  27. str(result[0], 'UTF-8').lstrip('\n').lstrip().encode('UTF-8')
  28. ),
  29. encoding='UTF-8',
  30. xml_declaration=True,
  31. pretty_print=True
  32. ), "xml"