~vauxoo/addons-vauxoo/7.0-project_issue_conf-dev_luis

« back to all changes in this revision

Viewing changes to bank_iva_report/report/numero_a_texto.py

  • Committer: Javier Duran
  • Author(s): javier at vauxoo
  • Date: 2012-01-21 01:20:12 UTC
  • Revision ID: javier@squezee-vir-20120121012012-9jjjvzimqk1p37ga
[ADD] se agrega el modulo bank_iva_report

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
 
6
#    All Rights Reserved
 
7
###############Credits######################################################
 
8
#    Coded by: Vauxoo C.A.           
 
9
#    Planified by: Nhomar Hernandez
 
10
#    Audited by: Vauxoo C.A.
 
11
#############################################################################
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as published by
 
14
#    the Free Software Foundation, either version 3 of the License, or
 
15
#    (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
################################################################################            
 
25
 
 
26
UNIDADES = (
 
27
    '',    
 
28
    'UNO ', 
 
29
    'DOS ',
 
30
    'TRES ',
 
31
    'CUATRO ',
 
32
    'CINCO ',
 
33
    'SEIS ', 
 
34
    'SIETE ',
 
35
    'OCHO ', 
 
36
    'NUEVE ',
 
37
    'DIEZ ', 
 
38
    'ONCE ', 
 
39
    'DOCE ', 
 
40
    'TRECE ',
 
41
    'CATORCE ',
 
42
    'QUINCE ',
 
43
    'DIECISEIS ',
 
44
    'DIECISIETE ',
 
45
    'DIECIOCHO ',
 
46
    'DIECINUEVE ',
 
47
    'VEINTE '    
 
48
)                
 
49
DECENAS = (      
 
50
    'VENTI',     
 
51
    'TREINTA ',  
 
52
    'CUARENTA ', 
 
53
    'CINCUENTA ',
 
54
    'SESENTA ',  
 
55
    'SETENTA ',  
 
56
    'OCHENTA ',  
 
57
    'NOVENTA ',  
 
58
    'CIEN '      
 
59
)                
 
60
CENTENAS = (     
 
61
    'CIENTO ',   
 
62
    'DOSCIENTOS ',
 
63
    'TRESCIENTOS ',
 
64
    'CUATROCIENTOS ',
 
65
    'QUINIENTOS ',  
 
66
    'SEISCIENTOS ', 
 
67
    'SETECIENTOS ', 
 
68
    'OCHOCIENTOS ', 
 
69
    'NOVECIENTOS '  
 
70
)                   
 
71
                    
 
72
def Numero_a_Texto(number_in):
 
73
                             
 
74
    converted = ''                             
 
75
 
 
76
    if type(number_in) != 'str':
 
77
      number = str(number_in)  
 
78
    else:                      
 
79
      number = number_in       
 
80
                                                          
 
81
    number_str=number                                     
 
82
                                                          
 
83
    try:                                                  
 
84
      number_int, number_dec = number_str.split(".")      
 
85
    except ValueError:                                    
 
86
      number_int = number_str                             
 
87
      number_dec = ""                                     
 
88
 
 
89
    number_str = number_int.zfill(9)
 
90
    millones = number_str[:3]      
 
91
    miles = number_str[3:6]        
 
92
    cientos = number_str[6:]       
 
93
 
 
94
    if(millones):
 
95
        if(millones == '001'):
 
96
            converted += 'UN MILLON '
 
97
        elif(int(millones) > 0):    
 
98
            converted += '%sMILLONES ' % __convertNumber(millones)
 
99
                                                                 
 
100
    if(miles):                                                   
 
101
        if(miles == '001'):                                      
 
102
            converted += 'MIL '                                  
 
103
        elif(int(miles) > 0):                                    
 
104
            converted += '%sMIL ' % __convertNumber(miles)       
 
105
    if(cientos):                                                 
 
106
        if(cientos == '001'):                                    
 
107
            converted += 'UN '                                   
 
108
        elif(int(cientos) > 0):                                  
 
109
            converted += '%s ' % __convertNumber(cientos)        
 
110
 
 
111
    if number_dec == "":
 
112
      number_dec = ""
 
113
#    if (len(number_dec) < 2 ):
 
114
#      number_dec+='0'        
 
115
 
 
116
    converted += number_dec
 
117
 
 
118
    return converted
 
119
                   
 
120
def __convertNumber(n):
 
121
    output = ''
 
122
 
 
123
    if(n == '100'):
 
124
        output = "CIEN"
 
125
    elif(n[0] != '0'):
 
126
        output = CENTENAS[int(n[0])-1]
 
127
 
 
128
    k = int(n[1:])
 
129
    if(k <= 20):
 
130
        output += UNIDADES[k]
 
131
    else:
 
132
        if((k > 30) & (n[2] != '0')):
 
133
            output += '%sY %s' % (DECENAS[int(n[1])-2], UNIDADES[int(n[2])])
 
134
        else:
 
135
            output += '%s%s' % (DECENAS[int(n[1])-2], UNIDADES[int(n[2])])
 
136
 
 
137
    return output
 
138
"""
 
139
print Numero_a_Texto(9121234.2)
 
140
"""
 
141