1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
22 from report import report_sxw
23 import xml.dom.minidom
31 from lxml import etree
34 class rml_parse(report_sxw.rml_parse):
35 def __init__(self, cr, uid, name, context):
36 super(rml_parse, self).__init__(cr, uid, name, context=None)
37 self.localcontext.update({
38 'comma_me': self.comma_me,
39 'format_date': self._get_and_change_date_format_for_swiss,
40 'strip_name' : self._strip_name,
41 'explode_name' : self._explode_name,
44 def comma_me(self,amount):
47 if type(amount) is float :
48 amount = str('%.2f'%amount)
54 new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
58 return self.comma_me(new)
59 def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
60 ellipsis = ellipsis or ''
62 return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
65 def _strip_name(self, name, maxlen=50):
66 return self._ellipsis(name, maxlen, '...')
68 def _get_and_change_date_format_for_swiss (self,date_to_format):
71 date_formatted = strptime (date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
74 def _explode_name(self,chaine,length):
75 # We will test if the size is less then account
77 if (len(str(chaine)) <= length):
81 chaine = unicode(chaine,'utf8').encode('iso-8859-1')
86 full_string = full_string + '\n'
87 full_string = full_string + carac
90 full_string = full_string + carac
94 def makeAscii(self,str):
96 Stringer = str.encode("utf-8")
97 except UnicodeDecodeError:
99 Stringer = str.encode("utf-16")
100 except UnicodeDecodeError:
109 def explode_this(self,chaine,length):
110 chaine = rstrip(chaine)
116 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 print str(to_reencode)
131 Good_char = to_reencode.decode('utf-8')
132 UnicodeAst.append(Good_char)
135 UnicodeAst.append(elem)
137 return "".join(UnicodeAst)
139 def ReencodeAscii(self,str):
140 print sys.stdin.encoding
142 Stringer = str.decode("ascii")
143 except UnicodeEncodeError:
144 print "REENCODING ERROR"
145 return str.encode("ascii")
146 except UnicodeDecodeError:
147 print "DECODING ERROR"
148 return str.encode("ascii")
154 def _add_header(self, node, header='external'):
155 if header=='internal':
156 rml_head = self.rml_header2
157 elif header=='internal landscape':
158 rml_head = self.rml_header3
160 rml_head = self.rml_header
161 rml_head = rml_head.replace('<pageGraphics>','''<pageGraphics> <image x="10" y="26cm" height="770.0" width="1120.0" >[[company.logo]] </image> ''')
163 head_dom = etree.XML(rml_head)
165 found = rml_dom.find('.//'+tag.tag)
166 if found is not None and len(found):
167 if tag.get('position'):
170 found.getparent().replace(found,tag)