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.

46 lines
1.7 KiB

  1. from base64 import b64encode
  2. from openerp import addons
  3. from openerp.osv import fields, osv
  4. from openerp.tools.translate import _
  5. class report_xml(osv.osv):
  6. ''' Inherit from ir.actions.report.xml to allow customizing the template
  7. file. By default, the file defined when registering the report is used;
  8. but the user can download / upload a new one. '''
  9. _inherit = 'ir.actions.report.xml'
  10. def _get_filename(self, cr, uid, ids, field_name, arg, context):
  11. return {
  12. br.id: br.name + '.odt'
  13. for br in self.browse(cr, uid, ids, context=context)
  14. if br.report_type == 'py3o'
  15. }
  16. def _get_template_data(self, cr, uid, ids, field_name, arg, context):
  17. ''' Just return the data stored in the binary field, unless it is
  18. empty; in that case, read the template file. '''
  19. return {
  20. br.id: (br.py3o_template_data or
  21. b64encode(file(addons.get_module_resource(
  22. *br.report_file.split('/')), 'rb').read()))
  23. for br in self.browse(cr, uid, ids, context=context)
  24. if br.report_type == 'py3o'
  25. }
  26. _columns = {
  27. 'py3o_filename': fields.function(_get_filename,
  28. type='char',
  29. method=True,
  30. readonly=True),
  31. 'py3o_template': fields.function(_get_template_data,
  32. type='binary',
  33. method=True,
  34. readonly=True),
  35. 'py3o_template_data': fields.binary(_('LibreOffice template')),
  36. }