1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
6
# Jordi Esteve <jesteve@zikzakmedia.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
from report import report_sxw
25
import xml.dom.minidom
35
class rml_parse(report_sxw.rml_parse):
37
def __init__(self, cr, uid, name, context):
38
super(rml_parse, self).__init__(cr, uid, name, context=None)
39
self.localcontext.update({
40
'comma_me': self.comma_me,
41
'format_date': self._get_and_change_date_format_for_swiss,
42
'strip_name' : self._strip_name,
43
'explode_name' : self._explode_name,
46
def comma_me(self,amount):
49
if type(amount) is float :
50
amount = str('%.2f'%amount)
56
new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
60
return self.comma_me(new)
61
def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
62
ellipsis = ellipsis or ''
64
return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
67
def _strip_name(self, name, maxlen=50):
68
return self._ellipsis(name, maxlen, '...')
70
def _get_and_change_date_format_for_swiss (self,date_to_format):
73
date_formatted = strptime (date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
76
def _explode_name(self,chaine,length):
77
# We will test if the size is less then account
79
if (len(str(chaine)) <= length):
83
chaine = unicode(chaine,'utf8').encode('iso-8859-1')
88
full_string = full_string + '\n'
89
full_string = full_string + carac
92
full_string = full_string + carac
96
def makeAscii(self,str):
98
Stringer = str.encode("utf-8")
99
except UnicodeDecodeError:
101
Stringer = str.encode("utf-16")
102
except UnicodeDecodeError:
109
def explode_this(self,chaine,length):
110
#chaine = self.repair_string(chaine)
111
chaine = rstrip(chaine)
117
chaine = str("".join(ast))
119
def repair_string(self,chaine):
122
_previouslyfound = False
127
Stringer = elem.encode("utf-8")
128
except UnicodeDecodeError:
129
to_reencode = elem + ast[i+1]
130
Good_char = to_reencode.decode('utf-8')
131
UnicodeAst.append(Good_char)
134
UnicodeAst.append(elem)
138
return "".join(UnicodeAst)
140
def ReencodeAscii(self,str):
142
Stringer = str.decode("ascii")
143
except UnicodeEncodeError:
144
return str.encode("ascii")
145
except UnicodeDecodeError:
146
return str.encode("ascii")
152
# def _add_header(self, node):
153
# rml_head = tools.file_open('specific_param/report/header/corporate_rml_header_ch.rml').read()
154
# head_dom = xml.dom.minidom.parseString(rml_head)
155
# #for frame in head_dom.getElementsByTagName('frame'):
156
# # frame.parentNode.removeChild(frame)
157
# node2 = head_dom.documentElement
158
# for tag in node2.childNodes:
159
# if tag.nodeType==tag.ELEMENT_NODE:
160
# found = self._find_node(node, tag.localName)
161
# # rml_frames = found.getElementsByTagName('frame')
163
# if tag.hasAttribute('position') and (tag.getAttribute('position')=='inside'):
164
# found.appendChild(tag)
166
# found.parentNode.replaceChild(tag, found)
167
# # for frame in rml_frames:
168
# # tag.appendChild(frame)