add Copyright and GPL license into the Header of Python files
[odoo/odoo.git] / bin / report / int_to_text.py
1 ##############################################################################
2 #
3 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # $Id$
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30 unites = {
31         0: '', 1:'un', 2:'deux', 3:'trois', 4:'quatre', 5:'cinq', 6:'six', 7:'sept', 8:'huit', 9:'neuf',
32         10:'dix', 11:'onze', 12:'douze', 13:'treize', 14:'quatorze', 15:'quinze', 16:'seize',
33         21:'vingt et un', 31:'trente et un', 41:'quarante et un', 51:'cinquante et un', 61:'soixante et un',
34         71:'septante et un', 91:'nonante et un', 80:'quatre-vingts'
35 }
36
37 dizaine = {
38         1: 'dix', 2:'vingt', 3:'trente',4:'quarante', 5:'cinquante', 6:'soixante', 7:'septante', 8:'quatre-vingt', 9:'nonante'
39 }
40
41 centaine = {
42         0:'', 1: 'cent', 2:'deux cent', 3:'trois cent',4:'quatre cent', 5:'cinq cent', 6:'six cent', 7:'sept cent', 8:'huit cent', 9:'neuf cent'
43 }
44
45 mille = {
46         0:'', 1:'mille'
47 }
48
49 def _100_to_text(chiffre):
50         if chiffre in unites:
51                 return unites[chiffre]
52         else:
53                 if chiffre%10>0:
54                         return dizaine[chiffre / 10]+'-'+unites[chiffre % 10]
55                 else:
56                         return dizaine[chiffre / 10]
57
58 def _1000_to_text(chiffre):
59         d = _100_to_text(chiffre % 100)
60         d2 = chiffre/100
61         if d2>0 and d:
62                 return centaine[d2]+' '+d
63         elif d2>1 and not(d):
64                 return centaine[d2]+'s'
65         else:
66                 return centaine[d2] or d
67
68 def _10000_to_text(chiffre):
69         if chiffre==0:
70                 return 'zero'
71         part1 = _1000_to_text(chiffre % 1000)
72         part2 = mille.get(chiffre / 1000,  _1000_to_text(chiffre / 1000)+' mille')
73         if part2 and part1:
74                 part1 = ' '+part1
75         return part2+part1
76
77 def int_to_text(i):
78         return _10000_to_text(i)
79
80 if __name__=='__main__':
81         for i in range(1,999999,139):
82                 print int_to_text(i)