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.

98 lines
3.4 KiB

  1. import os
  2. from openerp.osv import fields, osv
  3. from openerp.report.interface import report_int
  4. from ..py3o_parser import Py3oParser
  5. from openerp import addons
  6. class report_xml(osv.Model):
  7. """ Inherit from ir.actions.report.xml to allow customizing the template
  8. file. The user cam chose a template from a list.
  9. The list is configurable in the configuration tab, see py3o_template.py
  10. """
  11. _inherit = 'ir.actions.report.xml'
  12. _columns = {
  13. # TODO required when report_type type is py3o, add python constraint
  14. 'py3o_fusion_filetype': fields.many2one(
  15. 'py3o.fusion.filetype',
  16. u"Output Format",
  17. ),
  18. 'py3o_template_id': fields.many2one(
  19. 'py3o.template',
  20. u"Template",
  21. ),
  22. 'module': fields.char(
  23. u"Module",
  24. size=64,
  25. help=u"The implementer module that provides this report",
  26. ),
  27. 'py3o_template_fallback': fields.char(
  28. u"Fallback",
  29. size=128,
  30. help=(
  31. u"If the user does not provide a template this will be used "
  32. u"it should be a relative path to root of YOUR module"
  33. )
  34. ),
  35. 'report_type': fields.selection(
  36. [
  37. ('qweb-pdf', u"PDF"),
  38. ('qweb-html', u"HTML"),
  39. ('controller', u"Controller"),
  40. ('pdf', u"RML pdf (deprecated)"),
  41. ('sxw', u"RML sxw (deprecated)"),
  42. ('webkit', u"Webkit (deprecated)"),
  43. ('py3o', u"Py3o"),
  44. ],
  45. string=u"Report Type",
  46. required=True,
  47. help=u"HTML will open the report directly in your browser, "
  48. u"PDF will use wkhtmltopdf to render the HTML into a PDF "
  49. u"file and let you download it, Controller allows you to "
  50. u"define the url of a custom controller outputting "
  51. u"any kind of report.",
  52. )
  53. }
  54. def _lookup_report(self, cr, name):
  55. """Look up a report definition.
  56. """
  57. # First lookup in the deprecated place, because if the report
  58. # definition has not been updated, it is more likely the correct
  59. # definition is there. Only reports with custom parser
  60. # specified in Python are still there.
  61. if 'report.' + name in report_int._reports:
  62. new_report = report_int._reports['report.' + name]
  63. if not isinstance(new_report, Py3oParser):
  64. new_report = None
  65. else:
  66. cr.execute(
  67. 'SELECT * '
  68. 'FROM ir_act_report_xml '
  69. 'WHERE report_name=%s AND report_type=%s',
  70. (name, 'py3o')
  71. )
  72. r = cr.dictfetchone()
  73. if r:
  74. kwargs = {}
  75. if r['parser']:
  76. kwargs['parser'] = getattr(addons, r['parser'])
  77. new_report = Py3oParser(
  78. 'report.' + r['report_name'],
  79. r['model'],
  80. os.path.join('addons', r['report_rml'] or '/'),
  81. header=r['header'],
  82. register=False,
  83. **kwargs
  84. )
  85. else:
  86. new_report = None
  87. if new_report:
  88. return new_report
  89. else:
  90. return super(report_xml, self)._lookup_report(cr, name)