← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~luc-demeyer/openerp-reporting-engines/update-7.0-report_xls into lp:openerp-reporting-engines

 

Luc De Meyer (Noviat) has proposed merging lp:~luc-demeyer/openerp-reporting-engines/update-7.0-report_xls into lp:openerp-reporting-engines.

Requested reviews:
  OpenERP Community Reviewer/Maintainer (openerp-community-reviewer)

For more details, see:
https://code.launchpad.net/~luc-demeyer/openerp-reporting-engines/update-7.0-report_xls/+merge/199983

update of this module with
- module documentation in __openerp__.py
- icon added
- pep8 compliance
-- 
https://code.launchpad.net/~luc-demeyer/openerp-reporting-engines/update-7.0-report_xls/+merge/199983
Your team OpenERP Community Reviewer/Maintainer is requested to review the proposed merge of lp:~luc-demeyer/openerp-reporting-engines/update-7.0-report_xls into lp:openerp-reporting-engines.
=== modified file 'report_xls/__init__.py'
--- report_xls/__init__.py	2013-11-15 15:56:47 +0000
+++ report_xls/__init__.py	2013-12-23 22:07:23 +0000
@@ -12,7 +12,7 @@
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License

=== modified file 'report_xls/__openerp__.py'
--- report_xls/__openerp__.py	2013-11-15 15:56:47 +0000
+++ report_xls/__openerp__.py	2013-12-23 22:07:23 +0000
@@ -12,7 +12,7 @@
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
@@ -20,24 +20,61 @@
 #
 ##############################################################################
 {
-    'name': 'XLS report engine',
+    'name': 'Excel report engine',
     'version': '0.3',
     'license': 'AGPL-3',
     'author': 'Noviat',
     'website': 'http://www.noviat.com',
     'category': 'Reporting',
-    'description': """ 
-
-This module adds XLS 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.
-          
+    'description': """
+Excel report engine
+===================
+
+This module adds Excel export capabilities to the standard OpenERP 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.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@xxxxxxxxxx for help with the development of Excel reports in OpenERP, .
+
     """,
     'depends': ['base'],
     'external_dependencies': {'python': ['xlwt']},
     'demo_xml': [],
     'init_xml': [],
-    'update_xml' : [],
+    'update_xml': [],
     'active': False,
     'installable': True,
 }

=== modified file 'report_xls/report_xls.py'
--- report_xls/report_xls.py	2013-11-15 15:56:47 +0000
+++ report_xls/report_xls.py	2013-12-23 22:07:23 +0000
@@ -2,8 +2,8 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    
-#Copyright (c) 2013 Noviat nv/sa (www.noviat.com). All rights reserved.
+#
+#    Copyright (c) 2013 Noviat nv/sa (www.noviat.com). All rights reserved.
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -12,7 +12,7 @@
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
@@ -23,7 +23,7 @@
 import xlwt
 from xlwt.Style import default_style
 import cStringIO
-import datetime, time
+import datetime
 import inspect
 from types import CodeType
 from openerp.report.report_sxw import *
@@ -32,13 +32,15 @@
 import logging
 _logger = logging.getLogger(__name__)
 
+
 class AttrDict(dict):
     def __init__(self, *args, **kwargs):
         super(AttrDict, self).__init__(*args, **kwargs)
         self.__dict__ = self
 
+
 class report_xls(report_sxw):
-    
+
     xls_types = {
         'bool': xlwt.Row.set_cell_boolean,
         'date': xlwt.Row.set_cell_date,
@@ -53,36 +55,36 @@
     }
 
     # TO DO: move parameters infra to configurable data
-    
+
     # header/footer
-    DT_FORMAT = '%Y-%m-%d %H:%M:%S' 
+    DT_FORMAT = '%Y-%m-%d %H:%M:%S'
     hf_params = {
     'font_size': 8,
-    'font_style': 'I', # B: Bold, I:  Italic, U: Underline
+    'font_style': 'I',  # B: Bold, I:  Italic, U: Underline
     }
     xls_headers = {
-        'standard': ''
+        '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
+        '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
-    _pfc = '26' # default pattern fore_color
-    _bc = '22'  # borders color
+    _pfc = '26'  # default pattern fore_color
+    _bc = '22'   # borders color
     decimal_format = '#,##0.00'
-    date_format = 'YYYY-MM-DD'    
+    date_format = 'YYYY-MM-DD'
     xls_styles = {
         'xls_title': 'font: bold true, height 240;',
         'bold': 'font: bold true;',
         'underline': 'font: underline true;',
         'italic': 'font: italic true;',
-        'fill': 'pattern: pattern solid, fore_color %s;' %_pfc,
-        'fill_blue' : 'pattern: pattern solid, fore_color 27;',
-        'fill_grey' : 'pattern: pattern solid, fore_color 22;',        
-        '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),
+        'fill': 'pattern: pattern solid, fore_color %s;' % _pfc,
+        'fill_blue': 'pattern: pattern solid, fore_color 27;',
+        'fill_grey': 'pattern: pattern solid, fore_color 22;',
+        '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': 'align: horz left;',
         'center': 'align: horz center;',
         'right': 'align: horz right;',
@@ -91,8 +93,8 @@
         'bottom': 'align: vert bottom;',
     }
     # TO DO: move parameters supra to configurable data
-    
-    def create(self, cr, uid, ids, data, context=None):   
+
+    def create(self, cr, uid, ids, data, context=None):
         self.pool = pooler.get_pool(cr.dbname)
         self.cr = cr
         self.uid = uid
@@ -105,11 +107,13 @@
             if report_xml.report_type == 'xls':
                 return self.create_source_xls(cr, uid, ids, data, context)
         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 super(report_xls, self).create(cr, uid, ids, data, context)
 
     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)
         self.parser_instance = parser_instance
         objs = self.getObjects(cr, uid, ids, context)
@@ -122,12 +126,12 @@
         self.generate_xls_report(_p, _xs, data, objs, wb)
         wb.save(n)
         n.seek(0)
-        return (n.read(), 'xls')        
-   
+        return (n.read(), 'xls')
+
     def render(self, wanted, col_specs, rowtype, render_space='empty'):
         """
-        returns 'mako'-rendered col_specs
-        
+        returns 'evaluated' col_specs
+
         Input:
         - wanted: element from the wanted_list
         - col_specs : cf. specs[1:] documented in xls_row_template method
@@ -139,7 +143,7 @@
             caller_space = inspect.currentframe().f_back.f_back.f_locals
             localcontext = self.parser_instance.localcontext
             render_space.update(caller_space)
-            render_space.update(localcontext)       
+            render_space.update(localcontext)
         row = col_specs[wanted][rowtype][:]
         for i in range(len(row)):
             if isinstance(row[i], CodeType):
@@ -155,9 +159,9 @@
     def xls_row_template(self, specs, wanted_list):
         """
         Returns a row template.
-        
+
         Input :
-        - 'wanted_list': list of Columns that will be returned in the row_template 
+        - 'wanted_list': list of Columns that will be returned in the row_template
         - 'specs': list with Column Characteristics
             0: Column Name (from wanted_list)
             1: Column Colspan
@@ -190,14 +194,14 @@
                     if s_len > 7 and s[7] is not None:
                         c.append(s[7])
                     else:
-                        c.append(None)                        
+                        c.append(None)
                     r.append((col, c[1], c))
                     col += c[1]
                     break
             if not found:
                 _logger.warn("report_xls.xls_row_template, column '%s' not found in specs", w)
         return r
-    
+
     def xls_write_row(self, ws, row_pos, row_data, row_style=default_style, set_column_size=False):
         r = ws.row(row_pos)
         for col, size, spec in row_data:
@@ -209,9 +213,9 @@
                 data = report_xls.xls_types_default[spec[3]]
             if size != 1:
                 if formula:
-                    ws.write_merge(row_pos, row_pos, col, col+size-1, data, style)
+                    ws.write_merge(row_pos, row_pos, col, col + size - 1, data, style)
                 else:
-                    ws.write_merge(row_pos, row_pos, col, col+size-1, data, style)
+                    ws.write_merge(row_pos, row_pos, col, col + size - 1, data, style)
             else:
                 if formula:
                     ws.write(row_pos, col, formula, style)
@@ -220,5 +224,5 @@
             if set_column_size:
                 ws.col(col).width = spec[2] * 256
         return row_pos + 1
-               
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== added directory 'report_xls/static'
=== added directory 'report_xls/static/src'
=== added directory 'report_xls/static/src/img'
=== added file 'report_xls/static/src/img/icon.png'
Binary files report_xls/static/src/img/icon.png	1970-01-01 00:00:00 +0000 and report_xls/static/src/img/icon.png	2013-12-23 22:07:23 +0000 differ
=== modified file 'report_xls/utils.py'
--- report_xls/utils.py	2013-11-15 15:56:47 +0000
+++ report_xls/utils.py	2013-12-23 22:07:23 +0000
@@ -12,17 +12,18 @@
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
-#
+
 
 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):
     # Code based upon utils from xlwt distribution
@@ -41,9 +42,9 @@
     else:
         col_abs = ''
     if d > 0:
-        chr1 = chr(ord('A') + d  - 1)
+        chr1 = chr(ord('A') + d - 1)
     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:


Follow ups