mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[CHG] Rename base_report_xlsx to report_xlsx and add xlsx report type in selection
This commit is contained in:
committed by
Alex Cuellar
parent
f25ed2d685
commit
b0ecea8464
4
report_xlsx/report/__init__.py
Normal file
4
report_xlsx/report/__init__.py
Normal 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
|
||||
40
report_xlsx/report/report_xlsx.py
Normal file
40
report_xlsx/report/report_xlsx.py
Normal 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()
|
||||
Reference in New Issue
Block a user