~pedro.baeza/openerp-spain/6.1-fy_close_multi-company_fix

« back to all changes in this revision

Viewing changes to account_financial_report_web/report/rml_parse.py

  • Committer: Alberto Garcia
  • Date: 2014-04-15 07:30:16 UTC
  • mfrom: (383.1.1 6.1)
  • Revision ID: alberto.garcia@factorlibre.com-20140415073016-g4brb4snddzx4ah9
[ADD] Módulos para libro mayor en excel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
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>
 
7
#    $Id$
 
8
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from report import report_sxw
 
25
import xml.dom.minidom
 
26
import os, time
 
27
import osv
 
28
import re
 
29
import tools
 
30
import pooler
 
31
import re
 
32
import sys
 
33
 
 
34
 
 
35
class rml_parse(report_sxw.rml_parse):
 
36
 
 
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,
 
44
        })
 
45
 
 
46
    def comma_me(self,amount):
 
47
        if not amount:
 
48
            amount = 0.0
 
49
        if  type(amount) is float :
 
50
            amount = str('%.2f'%amount)
 
51
        else :
 
52
            amount = str(amount)
 
53
        if (amount == '0'):
 
54
             return ' '
 
55
        orig = amount
 
56
        new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
 
57
        if orig == new:
 
58
            return new
 
59
        else:
 
60
            return self.comma_me(new)
 
61
    def _ellipsis(self, string, maxlen=100, ellipsis = '...'):
 
62
        ellipsis = ellipsis or ''
 
63
        try:
 
64
            return string[:maxlen - len(ellipsis) ] + (ellipsis, '')[len(string) < maxlen]
 
65
        except Exception, e:
 
66
            return False
 
67
    def _strip_name(self, name, maxlen=50):
 
68
        return self._ellipsis(name, maxlen, '...')
 
69
            
 
70
    def _get_and_change_date_format_for_swiss (self,date_to_format):
 
71
        date_formatted=''
 
72
        if date_to_format:
 
73
            date_formatted = strptime (date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
 
74
        return date_formatted
 
75
    
 
76
    def _explode_name(self,chaine,length):
 
77
        # We will test if the size is less then account
 
78
        full_string = ''
 
79
        if (len(str(chaine)) <= length):
 
80
            return chaine
 
81
        #
 
82
        else:
 
83
            chaine = unicode(chaine,'utf8').encode('iso-8859-1')
 
84
            rup = 0
 
85
            for carac in chaine:
 
86
                rup = rup + 1
 
87
                if rup == length:
 
88
                    full_string = full_string + '\n'
 
89
                    full_string = full_string + carac
 
90
                    rup = 0
 
91
                else:
 
92
                    full_string = full_string + carac
 
93
            
 
94
        return full_string
 
95
    
 
96
    def makeAscii(self,str):
 
97
        try:
 
98
            Stringer = str.encode("utf-8")
 
99
        except UnicodeDecodeError:
 
100
            try:
 
101
                Stringer = str.encode("utf-16")
 
102
            except UnicodeDecodeError:
 
103
                Stringer = str
 
104
            else:
 
105
                return Stringer
 
106
        else:
 
107
            return Stringer
 
108
        return Stringer
 
109
    def explode_this(self,chaine,length):
 
110
        #chaine = self.repair_string(chaine)
 
111
        chaine = rstrip(chaine)
 
112
        ast = list(chaine)
 
113
        i = length
 
114
        while i <= len(ast):
 
115
            ast.insert(i,'\n')
 
116
            i = i + length
 
117
        chaine = str("".join(ast))
 
118
        return chaine
 
119
    def repair_string(self,chaine):
 
120
        ast = list(chaine)
 
121
        UnicodeAst = []
 
122
        _previouslyfound = False
 
123
        i = 0
 
124
        while i < len(ast):
 
125
            elem = ast[i]
 
126
            try:
 
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)
 
132
                i += i +2
 
133
            else:
 
134
                UnicodeAst.append(elem)
 
135
                i += i + 1
 
136
            
 
137
        
 
138
        return "".join(UnicodeAst)
 
139
        
 
140
    def ReencodeAscii(self,str):
 
141
        try:
 
142
            Stringer = str.decode("ascii")
 
143
        except UnicodeEncodeError:
 
144
            return str.encode("ascii")
 
145
        except UnicodeDecodeError:
 
146
            return str.encode("ascii")
 
147
        
 
148
        else:
 
149
            return Stringer
 
150
 
 
151
 
 
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')
 
162
    #             if found:
 
163
    #                 if tag.hasAttribute('position') and (tag.getAttribute('position')=='inside'):
 
164
    #                     found.appendChild(tag)
 
165
    #                 else:
 
166
    #                     found.parentNode.replaceChild(tag, found)
 
167
    #     #        for frame in rml_frames:
 
168
    #     #            tag.appendChild(frame)
 
169
    #    return True
 
170
 
 
171
 
 
172