mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
style & documentation refresh, xls footer datetime fix
This commit is contained in:
@@ -20,24 +20,60 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
{
|
{
|
||||||
'name': 'XLS report engine',
|
'name': 'Excel report engine',
|
||||||
'version': '0.3',
|
'version': '0.4',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': 'Noviat',
|
'author': 'Noviat',
|
||||||
'website': 'http://www.noviat.com',
|
'website': 'http://www.noviat.com',
|
||||||
'category': 'Reporting',
|
'category': 'Reporting',
|
||||||
'description': """
|
'description': """
|
||||||
|
Excel report engine
|
||||||
|
===================
|
||||||
|
|
||||||
This module adds XLS export capabilities to the standard OpenERP reporting engine.
|
This module adds Excel export capabilities to the standard OpenERP reporting engine.
|
||||||
|
|
||||||
In order to generate an XLS export you can define a report of type 'xls' or alternatively pass {'xls_export' : 1) via the context to create method of the report.
|
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.openerp.com
|
||||||
|
as example.
|
||||||
|
|
||||||
|
* XLS with multiple sheets
|
||||||
|
|
||||||
|
Download the ``account_journal_report_xls`` module from http://apps.openerp.com as example.
|
||||||
|
|
||||||
|
Development assistance
|
||||||
|
''''''''''''''''''''''
|
||||||
|
Contact info@noviat.com for help with the development of Excel reports in OpenERP, .
|
||||||
|
|
||||||
""",
|
""",
|
||||||
'depends': ['base'],
|
'depends': ['base'],
|
||||||
'external_dependencies': {'python': ['xlwt']},
|
'external_dependencies': {'python': ['xlwt']},
|
||||||
'demo_xml': [],
|
'demo': [],
|
||||||
'init_xml': [],
|
'data': [],
|
||||||
'update_xml' : [],
|
|
||||||
'active': False,
|
'active': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
import xlwt
|
import xlwt
|
||||||
from xlwt.Style import default_style
|
from xlwt.Style import default_style
|
||||||
import cStringIO
|
import cStringIO
|
||||||
import datetime, time
|
from datetime import datetime
|
||||||
|
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
import inspect
|
import inspect
|
||||||
from types import CodeType
|
from types import CodeType
|
||||||
from openerp.report.report_sxw import *
|
from openerp.report.report_sxw import *
|
||||||
@@ -32,11 +33,13 @@ from openerp.tools.translate import translate, _
|
|||||||
import logging
|
import logging
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AttrDict(dict):
|
class AttrDict(dict):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AttrDict, self).__init__(*args, **kwargs)
|
super(AttrDict, self).__init__(*args, **kwargs)
|
||||||
self.__dict__ = self
|
self.__dict__ = self
|
||||||
|
|
||||||
|
|
||||||
class report_xls(report_sxw):
|
class report_xls(report_sxw):
|
||||||
|
|
||||||
xls_types = {
|
xls_types = {
|
||||||
@@ -60,13 +63,6 @@ class report_xls(report_sxw):
|
|||||||
'font_size': 8,
|
'font_size': 8,
|
||||||
'font_style': 'I', # B: Bold, I: Italic, U: Underline
|
'font_style': 'I', # B: Bold, I: Italic, U: Underline
|
||||||
}
|
}
|
||||||
xls_headers = {
|
|
||||||
'standard': ''
|
|
||||||
}
|
|
||||||
xls_footers = {
|
|
||||||
'standard': ('&L&%(font_size)s&%(font_style)s' + datetime.now().strftime(DT_FORMAT) +
|
|
||||||
'&R&%(font_size)s&%(font_style)s&P / &N') %hf_params
|
|
||||||
}
|
|
||||||
|
|
||||||
# styles
|
# styles
|
||||||
_pfc = '26' # default pattern fore_color
|
_pfc = '26' # default pattern fore_color
|
||||||
@@ -81,7 +77,7 @@ class report_xls(report_sxw):
|
|||||||
'fill': 'pattern: pattern solid, fore_color %s;' % _pfc,
|
'fill': 'pattern: pattern solid, fore_color %s;' % _pfc,
|
||||||
'fill_blue': 'pattern: pattern solid, fore_color 27;',
|
'fill_blue': 'pattern: pattern solid, fore_color 27;',
|
||||||
'fill_grey': 'pattern: pattern solid, fore_color 22;',
|
'fill_grey': 'pattern: pattern solid, fore_color 22;',
|
||||||
'borders_all': 'borders: left thin, right thin, top thin, bottom thin, ' \
|
'borders_all': 'borders: left thin, right thin, top thin, bottom thin, '
|
||||||
'left_colour %s, right_colour %s, top_colour %s, bottom_colour %s;' % (_bc, _bc, _bc, _bc),
|
'left_colour %s, right_colour %s, top_colour %s, bottom_colour %s;' % (_bc, _bc, _bc, _bc),
|
||||||
'left': 'align: horz left;',
|
'left': 'align: horz left;',
|
||||||
'center': 'align: horz center;',
|
'center': 'align: horz center;',
|
||||||
@@ -105,11 +101,13 @@ class report_xls(report_sxw):
|
|||||||
if report_xml.report_type == 'xls':
|
if report_xml.report_type == 'xls':
|
||||||
return self.create_source_xls(cr, uid, ids, data, context)
|
return self.create_source_xls(cr, uid, ids, data, context)
|
||||||
elif context.get('xls_export'):
|
elif context.get('xls_export'):
|
||||||
|
self.table = data.get('model') or self.table # use model from 'data' when no ir.actions.report.xml entry
|
||||||
return self.create_source_xls(cr, uid, ids, data, context)
|
return self.create_source_xls(cr, uid, ids, data, context)
|
||||||
return super(report_xls, self).create(cr, uid, ids, data, context)
|
return super(report_xls, self).create(cr, uid, ids, data, context)
|
||||||
|
|
||||||
def create_source_xls(self, cr, uid, ids, data, context=None):
|
def create_source_xls(self, cr, uid, ids, data, context=None):
|
||||||
if not context: context = {}
|
if not context:
|
||||||
|
context = {}
|
||||||
parser_instance = self.parser(cr, uid, self.name2, context)
|
parser_instance = self.parser(cr, uid, self.name2, context)
|
||||||
self.parser_instance = parser_instance
|
self.parser_instance = parser_instance
|
||||||
objs = self.getObjects(cr, uid, ids, context)
|
objs = self.getObjects(cr, uid, ids, context)
|
||||||
@@ -119,6 +117,13 @@ class report_xls(report_sxw):
|
|||||||
wb = xlwt.Workbook(encoding='utf-8')
|
wb = xlwt.Workbook(encoding='utf-8')
|
||||||
_p = AttrDict(parser_instance.localcontext)
|
_p = AttrDict(parser_instance.localcontext)
|
||||||
_xs = self.xls_styles
|
_xs = self.xls_styles
|
||||||
|
self.xls_headers = {
|
||||||
|
'standard': '',
|
||||||
|
}
|
||||||
|
self.xls_footers = {
|
||||||
|
'standard': ('&L&%(font_size)s&%(font_style)s' + datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT) +
|
||||||
|
'&R&%(font_size)s&%(font_style)s&P / &N') % self.hf_params,
|
||||||
|
}
|
||||||
self.generate_xls_report(_p, _xs, data, objs, wb)
|
self.generate_xls_report(_p, _xs, data, objs, wb)
|
||||||
wb.save(n)
|
wb.save(n)
|
||||||
n.seek(0)
|
n.seek(0)
|
||||||
@@ -126,7 +131,7 @@ class report_xls(report_sxw):
|
|||||||
|
|
||||||
def render(self, wanted, col_specs, rowtype, render_space='empty'):
|
def render(self, wanted, col_specs, rowtype, render_space='empty'):
|
||||||
"""
|
"""
|
||||||
returns 'mako'-rendered col_specs
|
returns 'evaluated' col_specs
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
- wanted: element from the wanted_list
|
- wanted: element from the wanted_list
|
||||||
|
|||||||
BIN
report_xls/static/src/img/icon.png
Normal file
BIN
report_xls/static/src/img/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -19,11 +19,12 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
|
||||||
|
|
||||||
def _render(code):
|
def _render(code):
|
||||||
return compile(code, '<string>', 'eval')
|
return compile(code, '<string>', 'eval')
|
||||||
|
|
||||||
|
|
||||||
def rowcol_to_cell(row, col, row_abs=False, col_abs=False):
|
def rowcol_to_cell(row, col, row_abs=False, col_abs=False):
|
||||||
# Code based upon utils from xlwt distribution
|
# Code based upon utils from xlwt distribution
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user