Merge pull request #1 from osiell/9.0-add-base_report_xlsx-ape-amend
[9.0] report_xlsx - Improvements, fixespull/38/head
commit
d383975a8a
|
@ -21,8 +21,6 @@ virtualenv:
|
||||||
system_site_packages: true
|
system_site_packages: true
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install xlwt
|
|
||||||
- pip install xlsxwriter
|
|
||||||
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
|
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
|
||||||
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
|
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
|
||||||
- travis_install_nightly ${VERSION}
|
- travis_install_nightly ${VERSION}
|
||||||
|
|
|
@ -8,6 +8,13 @@ Base report xlsx
|
||||||
|
|
||||||
This module provides a basic report class to generate xlsx report.
|
This module provides a basic report class to generate xlsx report.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Make sure you have ``xlsxwriter`` Python module installed::
|
||||||
|
|
||||||
|
$ pip install xlsxwriter
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
@ -31,6 +38,9 @@ A python class ::
|
||||||
partner_xlsx('report.res.partner.xlsx',
|
partner_xlsx('report.res.partner.xlsx',
|
||||||
'res.partner')
|
'res.partner')
|
||||||
|
|
||||||
|
To manipulate the ``workbook`` and ``sheet`` objects, refer to the
|
||||||
|
`documentation <http://xlsxwriter.readthedocs.org/>`_ of ``xlsxwriter``.
|
||||||
|
|
||||||
A report XML record ::
|
A report XML record ::
|
||||||
|
|
||||||
<report
|
<report
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from openerp import api, fields, models
|
from openerp import fields, models
|
||||||
|
|
||||||
|
|
||||||
class IrActionsReportXml(models.Model):
|
class IrActionsReportXml(models.Model):
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
|
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
from openerp.report.report_sxw import report_sxw
|
from openerp.report.report_sxw import report_sxw
|
||||||
from openerp.api import Environment
|
from openerp.api import Environment
|
||||||
from cStringIO import StringIO
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
@ -24,11 +25,15 @@ class ReportXlsx(report_sxw):
|
||||||
if report.ids:
|
if report.ids:
|
||||||
self.title = report.name
|
self.title = report.name
|
||||||
if report.report_type == 'xlsx':
|
if report.report_type == 'xlsx':
|
||||||
objs = self.env[self.table].browse(ids)
|
return self.create_xlsx_report(ids, data, report)
|
||||||
return self.create_xlsx_report(data, objs)
|
|
||||||
return super(ReportXlsx, self).create(cr, uid, ids, data, context)
|
return super(ReportXlsx, self).create(cr, uid, ids, data, context)
|
||||||
|
|
||||||
def create_xlsx_report(self, data, objs):
|
def create_xlsx_report(self, ids, data, report):
|
||||||
|
self.parser_instance = self.parser(
|
||||||
|
self.env.cr, self.env.uid, self.name2, self.env.context)
|
||||||
|
objs = self.getObjects(
|
||||||
|
self.env.cr, self.env.uid, ids, self.env.context)
|
||||||
|
self.parser_instance.set_context(objs, data, objs.ids, 'xlsx')
|
||||||
file_data = StringIO()
|
file_data = StringIO()
|
||||||
workbook = xlsxwriter.Workbook(file_data)
|
workbook = xlsxwriter.Workbook(file_data)
|
||||||
self.generate_xlsx_report(workbook, data, objs)
|
self.generate_xlsx_report(workbook, data, objs)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
xlwt
|
||||||
|
xlsxwriter
|
Loading…
Reference in New Issue