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.

49 lines
1.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  3. # License AGPL-3.0 or later (http://www.gnu.org/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.xml"
  10. report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
  11. def _lookup_report(self, name):
  12. """Enable ``qweb-xml`` report lookup."""
  13. try:
  14. return super(ReportAction, self)._lookup_report(name)
  15. except Exception as ex:
  16. # Somebody thought it was a good idea to use standard exceptions
  17. if "qweb-xml" not in ex.message:
  18. raise ex
  19. else:
  20. self._cr.execute(
  21. "SELECT * FROM ir_act_report_xml WHERE report_name=%s",
  22. (name,))
  23. return self._cr.dictfetchone()["report_name"]
  24. @api.model
  25. def render_report(self, res_ids, name, data):
  26. """Special handling for ``qweb-xml`` reports."""
  27. xml_report = self.search([('report_name', '=', name),
  28. ('report_type', '=', 'qweb-xml')], limit=1)
  29. if xml_report:
  30. xml_report = xml_report.ensure_one()
  31. result = self.env["report"].get_html(res_ids,
  32. xml_report.report_name,
  33. data=data)
  34. return (
  35. etree.tostring(
  36. etree.fromstring(result.strip()),
  37. encoding='UTF-8', xml_declaration=True, pretty_print=True
  38. ), "xml")
  39. else:
  40. return super(ReportAction, self).render_report(
  41. res_ids, name, data)