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.

64 lines
2.1 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(
  7. selection_add=[("qweb-xml", "XML")], ondelete={"qweb-xml": "set default"}
  8. )
  9. xsd_schema = fields.Binary(
  10. string="XSD Validation Schema",
  11. attachment=True,
  12. help=(
  13. "File with XSD Schema for checking content of result report. "
  14. "Can be empty if validation is not required."
  15. ),
  16. )
  17. xml_encoding = fields.Selection(
  18. selection=[
  19. ("UTF-8", "UTF-8") # will be used as default even if nothing is selected
  20. ],
  21. string="XML Encoding",
  22. help=(
  23. "Encoding for XML reports. If nothing is selected, "
  24. "then UTF-8 will be applied."
  25. ),
  26. )
  27. xml_declaration = fields.Boolean(
  28. string="XML Declaration",
  29. help=(
  30. """Add `<?xml encoding="..." version="..."?>` at the start """
  31. """of final report file."""
  32. ),
  33. )
  34. def _render_qweb_xml(self, docids, data=None):
  35. """
  36. Call `generate_report` method of report abstract class
  37. `report.<report technical name>` or of standard class for XML report
  38. rendering - `report.report_xml.abstract`
  39. Args:
  40. * docids(list) - IDs of instances for those report will be generated
  41. * data(dict, None) - variables for report rendering
  42. Returns:
  43. * str - result content of report
  44. * str - type of result content
  45. """
  46. report_model_name = "report.{}".format(self.report_name)
  47. report_model = self.env.get(report_model_name)
  48. if report_model is None:
  49. report_model = self.env["report.report_xml.abstract"]
  50. content, ttype = report_model.generate_report(
  51. ir_report=self, # will be used to get settings of report
  52. docids=docids,
  53. data=data,
  54. )
  55. return content, ttype