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.

48 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from cStringIO import StringIO
  5. from openerp.report.report_sxw import report_sxw
  6. from openerp.api import Environment
  7. import logging
  8. _logger = logging.getLogger(__name__)
  9. try:
  10. import xlsxwriter
  11. except ImportError:
  12. _logger.debug('Can not import xlsxwriter`.')
  13. class ReportXlsx(report_sxw):
  14. def create(self, cr, uid, ids, data, context=None):
  15. self.env = Environment(cr, uid, context)
  16. report_obj = self.env['ir.actions.report.xml']
  17. report = report_obj.search([('report_name', '=', self.name[7:])])
  18. if report.ids:
  19. self.title = report.name
  20. if report.report_type == 'xlsx':
  21. return self.create_xlsx_report(ids, data, report)
  22. return super(ReportXlsx, self).create(cr, uid, ids, data, context)
  23. def create_xlsx_report(self, ids, data, report):
  24. self.parser_instance = self.parser(
  25. self.env.cr, self.env.uid, self.name2, self.env.context)
  26. objs = self.getObjects(
  27. self.env.cr, self.env.uid, ids, self.env.context)
  28. self.parser_instance.set_context(objs, data, ids, 'xlsx')
  29. file_data = StringIO()
  30. workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options())
  31. self.generate_xlsx_report(workbook, data, objs)
  32. workbook.close()
  33. file_data.seek(0)
  34. return (file_data.read(), 'xlsx')
  35. def get_workbook_options(self):
  36. return {}
  37. def generate_xlsx_report(self, workbook, data, objs):
  38. raise NotImplementedError()