|
|
@ -3,7 +3,7 @@ |
|
|
|
# |
|
|
|
# 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 |
|
|
@ -23,7 +23,8 @@ |
|
|
|
import xlwt |
|
|
|
from xlwt.Style import default_style |
|
|
|
import cStringIO |
|
|
|
import datetime, time |
|
|
|
from datetime import datetime |
|
|
|
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT |
|
|
|
import inspect |
|
|
|
from types import CodeType |
|
|
|
from openerp.report.report_sxw import * |
|
|
@ -32,11 +33,13 @@ from openerp.tools.translate import translate, _ |
|
|
|
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 = { |
|
|
@ -60,13 +63,6 @@ class report_xls(report_sxw): |
|
|
|
'font_size': 8, |
|
|
|
'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 |
|
|
|
_pfc = '26' # default pattern fore_color |
|
|
@ -78,11 +74,11 @@ class report_xls(report_sxw): |
|
|
|
'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;', |
|
|
@ -105,11 +101,13 @@ class report_xls(report_sxw): |
|
|
|
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) |
|
|
@ -119,6 +117,13 @@ class report_xls(report_sxw): |
|
|
|
wb = xlwt.Workbook(encoding='utf-8') |
|
|
|
_p = AttrDict(parser_instance.localcontext) |
|
|
|
_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) |
|
|
|
wb.save(n) |
|
|
|
n.seek(0) |
|
|
@ -126,7 +131,7 @@ class report_xls(report_sxw): |
|
|
|
|
|
|
|
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 |
|
|
@ -209,9 +214,9 @@ class report_xls(report_sxw): |
|
|
|
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) |
|
|
|