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.

85 lines
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2013 XCG Consulting (http://odoo.consulting)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import os
  5. from openerp import api, fields, models
  6. from openerp.report.interface import report_int
  7. from ..py3o_parser import Py3oParser
  8. from openerp.exceptions import ValidationError
  9. from openerp import addons
  10. class ReportXml(models.Model):
  11. """ Inherit from ir.actions.report.xml to allow customizing the template
  12. file. The user cam chose a template from a list.
  13. The list is configurable in the configuration tab, see py3o_template.py
  14. """
  15. _inherit = 'ir.actions.report.xml'
  16. @api.one
  17. @api.constrains("py3o_fusion_filetype", "report_type")
  18. def _check_py3o_fusion_filetype(self):
  19. if self.report_type == "py3o" and not self.py3o_fusion_filetype:
  20. raise ValidationError(
  21. "Field 'Output Format' is required for Py3O report")
  22. py3o_fusion_filetype = fields.Many2one(
  23. 'py3o.fusion.filetype',
  24. "Output Format")
  25. py3o_template_id = fields.Many2one(
  26. 'py3o.template',
  27. "Template")
  28. module = fields.Char(
  29. "Module",
  30. help="The implementer module that provides this report")
  31. py3o_template_fallback = fields.Char(
  32. "Fallback",
  33. size=128,
  34. help=(
  35. "If the user does not provide a template this will be used "
  36. "it should be a relative path to root of YOUR module"
  37. ))
  38. report_type = fields.Selection(selection_add=[('py3o', "Py3o")])
  39. @api.cr
  40. def _lookup_report(self, cr, name):
  41. """Look up a report definition.
  42. """
  43. # First lookup in the deprecated place, because if the report
  44. # definition has not been updated, it is more likely the correct
  45. # definition is there. Only reports with custom parser
  46. # specified in Python are still there.
  47. if 'report.' + name in report_int._reports:
  48. new_report = report_int._reports['report.' + name]
  49. if not isinstance(new_report, Py3oParser):
  50. new_report = None
  51. else:
  52. cr.execute(
  53. 'SELECT * '
  54. 'FROM ir_act_report_xml '
  55. 'WHERE report_name=%s AND report_type=%s',
  56. (name, 'py3o')
  57. )
  58. r = cr.dictfetchone()
  59. if r:
  60. kwargs = {}
  61. if r['parser']:
  62. kwargs['parser'] = getattr(addons, r['parser'])
  63. new_report = Py3oParser(
  64. 'report.' + r['report_name'],
  65. r['model'],
  66. os.path.join('addons', r['report_rml'] or '/'),
  67. header=r['header'],
  68. register=False,
  69. **kwargs
  70. )
  71. else:
  72. new_report = None
  73. if new_report:
  74. return new_report
  75. else:
  76. return super(ReportXml, self)._lookup_report(cr, name)