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. 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. 'py3o_fusion_filetype': fields.many2one(
  14. 'py3o.fusion.filetype',
  15. u"Output Format",
  16. ),
  17. 'py3o_template_id': fields.many2one(
  18. 'py3o.template',
  19. u"Template",
  20. ),
  21. 'report_type': fields.selection(
  22. [
  23. ('qweb-pdf', u"PDF"),
  24. ('qweb-html', u"HTML"),
  25. ('controller', u"Controller"),
  26. ('pdf', u"RML pdf (deprecated)"),
  27. ('sxw', u"RML sxw (deprecated)"),
  28. ('webkit', u"Webkit (deprecated)"),
  29. ('py3o', u"Py3o"),
  30. ],
  31. string=u"Report Type",
  32. required=True,
  33. help=u"HTML will open the report directly in your browser, "
  34. u"PDF will use wkhtmltopdf to render the HTML into a PDF "
  35. u"file and let you download it, Controller allows you to "
  36. u"define the url of a custom controller outputting "
  37. u"any kind of report.",
  38. )
  39. }
  40. def _lookup_report(self, cr, name):
  41. """
  42. Look up a report definition.
  43. """
  44. # First lookup in the deprecated place, because if the report
  45. # definition has not been updated, it is more likely the correct
  46. # definition is there. Only reports with custom parser
  47. # specified in Python are still there.
  48. if 'report.' + name in report_int._reports:
  49. new_report = report_int._reports['report.' + name]
  50. if not isinstance(new_report, Py3oParser):
  51. new_report = None
  52. else:
  53. cr.execute(
  54. 'SELECT * '
  55. 'FROM ir_act_report_xml '
  56. 'WHERE report_name=%s AND report_type=%s',
  57. (name, 'py3o')
  58. )
  59. r = cr.dictfetchone()
  60. if r:
  61. kwargs = {}
  62. if r['parser']:
  63. kwargs['parser'] = getattr(addons, r['parser'])
  64. new_report = Py3oParser(
  65. 'report.' + r['report_name'],
  66. r['model'],
  67. os.path.join('addons', r['report_rml'] or '/'),
  68. header=r['header'],
  69. register=False,
  70. **kwargs
  71. )
  72. else:
  73. new_report = None
  74. if new_report:
  75. return new_report
  76. else:
  77. return super(report_xml, self)._lookup_report(cr, name)