[CHG] Rename base_report_xlsx to report_xlsx and add xlsx report type in selection

This commit is contained in:
Adrien Peiffer (ACSONE)
2016-04-04 20:28:23 +02:00
committed by Alex Cuellar
parent f25ed2d685
commit b0ecea8464
8 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# -*- 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 . import report_xlsx

View File

@@ -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()