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.

62 lines
2.0 KiB

  1. # Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
  2. # License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
  3. from odoo import fields, models
  4. class IrActionsReport(models.Model):
  5. _inherit = "ir.actions.report"
  6. report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
  7. xsd_schema = fields.Binary(
  8. string="XSD Validation Schema",
  9. attachment=True,
  10. help=(
  11. "File with XSD Schema for checking content of result report. "
  12. "Can be empty if validation is not required."
  13. ),
  14. )
  15. xml_encoding = fields.Selection(
  16. selection=[
  17. ("UTF-8", "UTF-8") # will be used as default even if nothing is selected
  18. ],
  19. string="XML Encoding",
  20. help=(
  21. "Encoding for XML reports. If nothing is selected, "
  22. "then UTF-8 will be applied."
  23. ),
  24. )
  25. xml_declaration = fields.Boolean(
  26. string="XML Declaration",
  27. help=(
  28. """Add `<?xml encoding="..." version="..."?>` at the start """
  29. """of final report file."""
  30. ),
  31. )
  32. def render_qweb_xml(self, docids, data=None):
  33. """
  34. Call `generate_report` method of report abstract class
  35. `report.<report technical name>` or of standard class for XML report
  36. rendering - `report.report_xml.abstract`
  37. Args:
  38. * docids(list) - IDs of instances for those report will be generated
  39. * data(dict, None) - variables for report rendering
  40. Returns:
  41. * str - result content of report
  42. * str - type of result content
  43. """
  44. report_model_name = "report.{}".format(self.report_name)
  45. report_model = self.env.get(report_model_name)
  46. if report_model is None:
  47. report_model = self.env["report.report_xml.abstract"]
  48. content, ttype = report_model.generate_report(
  49. ir_report=self, # will be used to get settings of report
  50. docids=docids,
  51. data=data,
  52. )
  53. return content, ttype