|
|
@ -0,0 +1,40 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>) |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from openerp.report.report_sxw import report_sxw |
|
|
|
from openerp.api import Environment |
|
|
|
from cStringIO import StringIO |
|
|
|
|
|
|
|
import logging |
|
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
try: |
|
|
|
import xlsxwriter |
|
|
|
except ImportError: |
|
|
|
_logger.debug('Can not import xlsxwriter`.') |
|
|
|
|
|
|
|
|
|
|
|
class ReportXlsx(report_sxw): |
|
|
|
|
|
|
|
def create(self, cr, uid, ids, data, context=None): |
|
|
|
self.env = Environment(cr, uid, context) |
|
|
|
report_obj = self.env['ir.actions.report.xml'] |
|
|
|
report = report_obj.search([('report_name', '=', self.name[7:])]) |
|
|
|
if report.ids: |
|
|
|
self.title = report.name |
|
|
|
if report.report_type == 'xlsx': |
|
|
|
objs = self.env[self.table].browse(ids) |
|
|
|
return self.create_xlsx_report(data, objs) |
|
|
|
return super(ReportXlsx, self).create(cr, uid, ids, data, context) |
|
|
|
|
|
|
|
def create_xlsx_report(self, data, objs): |
|
|
|
file_data = StringIO() |
|
|
|
workbook = xlsxwriter.Workbook(file_data) |
|
|
|
self.generate_xlsx_report(workbook, data, objs) |
|
|
|
workbook.close() |
|
|
|
file_data.seek(0) |
|
|
|
return (file_data.read(), 'xlsx') |
|
|
|
|
|
|
|
def generate_xlsx_report(self, workbook, data, objs): |
|
|
|
raise NotImplementedError() |