mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
Merge pull request #62 from Tecnativa/8.0-report_xls-protected_import
[8.0][FIX][report_xls] Protect xlwt import.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -22,4 +22,3 @@
|
||||
|
||||
from . import ir_report
|
||||
from . import report_xls
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -26,57 +26,7 @@
|
||||
'author': "Noviat,Odoo Community Association (OCA)",
|
||||
'website': 'http://www.noviat.com',
|
||||
'category': 'Reporting',
|
||||
'description': """
|
||||
Excel report engine
|
||||
===================
|
||||
|
||||
This module adds Excel export capabilities to the standard odoo reporting
|
||||
engine.
|
||||
|
||||
Report development
|
||||
''''''''''''''''''
|
||||
In order to create an Excel report you can\n
|
||||
- define a report of type 'xls'
|
||||
- pass ``{'xls_export': 1}`` via the context to the report create method
|
||||
|
||||
The ``report_xls`` class contains a number of attributes and methods to
|
||||
facilitate the creation XLS reports in OpenERP.
|
||||
|
||||
* cell types
|
||||
|
||||
Supported cell types : text, number, boolean, date.
|
||||
|
||||
* cell styles
|
||||
|
||||
The predefined cell style definitions result in a consistent
|
||||
look and feel of the OpenERP Excel reports.
|
||||
|
||||
* cell formulas
|
||||
|
||||
Cell formulas can be easily added with the help of the ``rowcol_to_cell()``
|
||||
function which you can import from the ``utils.py`` module.
|
||||
|
||||
* Excel templates
|
||||
|
||||
It is possible to define Excel templates which can be adapted
|
||||
by 'inherited' modules.
|
||||
Download the ``account_move_line_report_xls`` module
|
||||
from http://apps.odoo.com as example.
|
||||
|
||||
* XLS with multiple sheets
|
||||
|
||||
Download the ``account_journal_report_xls`` module
|
||||
from http://apps.odoo.com as example.
|
||||
|
||||
Development assistance
|
||||
''''''''''''''''''''''
|
||||
Contact info@noviat.com for help with the development of
|
||||
Excel reports in odoo.
|
||||
|
||||
""",
|
||||
'depends': ['base'],
|
||||
'external_dependencies': {'python': ['xlwt']},
|
||||
'active': False,
|
||||
'installable': True,
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -20,17 +20,15 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import orm
|
||||
from openerp import models
|
||||
|
||||
|
||||
class ir_actions_report_xml(orm.Model):
|
||||
class IrActionsReportXml(models.Model):
|
||||
_inherit = 'ir.actions.report.xml'
|
||||
|
||||
def _check_selection_field_value(self, cr, uid,
|
||||
field, value, context=None):
|
||||
if field == 'report_type' and value == 'xls':
|
||||
return
|
||||
return super(ir_actions_report_xml, self)._check_selection_field_value(
|
||||
return super(IrActionsReportXml, self)._check_selection_field_value(
|
||||
cr, uid, field, value, context=context)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -20,8 +20,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import xlwt
|
||||
from xlwt.Style import default_style
|
||||
import cStringIO
|
||||
from datetime import datetime
|
||||
from openerp.osv.fields import datetime as datetime_field
|
||||
@@ -33,6 +31,12 @@ from openerp import pooler
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
import xlwt
|
||||
from xlwt.Style import default_style
|
||||
except ImportError:
|
||||
_logger.debug("Cannot import xlwt. This module will not be functional.")
|
||||
|
||||
|
||||
class AttrDict(dict):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -40,7 +44,7 @@ class AttrDict(dict):
|
||||
self.__dict__ = self
|
||||
|
||||
|
||||
class report_xls(report_sxw):
|
||||
class ReportXls(report_sxw):
|
||||
|
||||
xls_types = {
|
||||
'bool': xlwt.Row.set_cell_boolean,
|
||||
@@ -108,7 +112,7 @@ class report_xls(report_sxw):
|
||||
# use model from 'data' when no ir.actions.report.xml entry
|
||||
self.table = data.get('model') or self.table
|
||||
return self.create_source_xls(cr, uid, ids, data, context)
|
||||
return super(report_xls, self).create(cr, uid, ids, data, context)
|
||||
return super(ReportXls, self).create(cr, uid, ids, data, context)
|
||||
|
||||
def create_source_xls(self, cr, uid, ids, data, context=None):
|
||||
if not context:
|
||||
@@ -162,7 +166,8 @@ class report_xls(report_sxw):
|
||||
row = col_specs[wanted][rowtype][:]
|
||||
for i in range(len(row)):
|
||||
if isinstance(row[i], CodeType):
|
||||
row[i] = eval(row[i], render_space)
|
||||
# TODO Use safe_eval or document why not and remove pylint hack
|
||||
row[i] = eval(row[i], render_space) # pylint: disable=W0123
|
||||
row.insert(0, wanted)
|
||||
return row
|
||||
|
||||
@@ -201,7 +206,7 @@ class report_xls(report_sxw):
|
||||
c.append({'formula': s[5]})
|
||||
else:
|
||||
c.append({
|
||||
'write_cell_func': report_xls.xls_types[c[3]]})
|
||||
'write_cell_func': ReportXls.xls_types[c[3]]})
|
||||
# Set custom cell style
|
||||
if s_len > 6 and s[6] is not None:
|
||||
c.append(s[6])
|
||||
@@ -216,7 +221,7 @@ class report_xls(report_sxw):
|
||||
col += c[1]
|
||||
break
|
||||
if not found:
|
||||
_logger.warn("report_xls.xls_row_template, "
|
||||
_logger.warn("ReportXls.xls_row_template, "
|
||||
"column '%s' not found in specs", w)
|
||||
return r
|
||||
|
||||
@@ -230,7 +235,7 @@ class report_xls(report_sxw):
|
||||
style = spec[6] and spec[6] or row_style
|
||||
if not data:
|
||||
# if no data, use default values
|
||||
data = report_xls.xls_types_default[spec[3]]
|
||||
data = ReportXls.xls_types_default[spec[3]]
|
||||
if size != 1:
|
||||
if formula:
|
||||
ws.write_merge(
|
||||
@@ -246,5 +251,3 @@ class report_xls(report_sxw):
|
||||
if set_column_size:
|
||||
ws.col(col).width = spec[2] * 256
|
||||
return row_pos + 1
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
@@ -47,5 +47,3 @@ def rowcol_to_cell(row, col, row_abs=False, col_abs=False):
|
||||
chr2 = chr(ord('A') + m)
|
||||
# Zero index to 1-index
|
||||
return col_abs + chr1 + chr2 + row_abs + str(row + 1)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user