diff --git a/addons/account_check_printing/models/account_payment.py b/addons/account_check_printing/models/account_payment.py index 249f7314001..f3b197cc5a0 100644 --- a/addons/account_check_printing/models/account_payment.py +++ b/addons/account_check_printing/models/account_payment.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import math - from odoo import models, fields, api, _ -from odoo.tools import amount_to_text_en, float_round from odoo.exceptions import UserError, ValidationError @@ -29,7 +26,7 @@ class AccountRegisterPayments(models.TransientModel): def _onchange_amount(self): if hasattr(super(AccountRegisterPayments, self), '_onchange_amount'): super(AccountRegisterPayments, self)._onchange_amount() - self.check_amount_in_words = self.env['account.payment']._get_check_amount_in_words(self.amount) + self.check_amount_in_words = self.currency_id.amount_to_text(self.amount) def _prepare_payment_vals(self, invoices): res = super(AccountRegisterPayments, self)._prepare_payment_vals(invoices) @@ -50,15 +47,6 @@ class AccountPayment(models.Model): help="The selected journal is configured to print check numbers. If your pre-printed check paper already has numbers " "or if the current numbering is wrong, you can change it in the journal configuration page.") - def _get_check_amount_in_words(self, amount): - # TODO: merge, refactor and complete the amount_to_text and amount_to_text_en classes - check_amount_in_words = amount_to_text_en.amount_to_text(math.floor(amount), lang='en', currency='') - check_amount_in_words = check_amount_in_words.replace(' and Zero Cent', '') # Ugh - decimals = amount % 1 - if decimals >= 10**-2: - check_amount_in_words += _(' and %s/100') % str(int(round(float_round(decimals*100, precision_rounding=1)))) - return check_amount_in_words - @api.onchange('journal_id') def _onchange_journal_id(self): if hasattr(super(AccountPayment, self), '_onchange_journal_id'): @@ -69,7 +57,7 @@ class AccountPayment(models.Model): @api.onchange('amount') def _onchange_amount(self): res = super(AccountPayment, self)._onchange_amount() - self.check_amount_in_words = self._get_check_amount_in_words(self.amount) + self.check_amount_in_words = self.currency_id.amount_to_text(self.amount) return res def _check_communication(self, payment_method_id, communication): diff --git a/addons/hr_expense_check/models/payment.py b/addons/hr_expense_check/models/payment.py index 06690029a61..d2609d63181 100644 --- a/addons/hr_expense_check/models/payment.py +++ b/addons/hr_expense_check/models/payment.py @@ -27,7 +27,7 @@ class HrExpenseRegisterPaymentWizard(models.TransientModel): def _onchange_amount(self): if hasattr(super(HrExpenseRegisterPaymentWizard, self), '_onchange_amount'): super(HrExpenseRegisterPaymentWizard, self)._onchange_amount() - self.check_amount_in_words = self.env['account.payment']._get_check_amount_in_words(self.amount) + self.check_amount_in_words = self.currency_id.amount_to_text(self.amount) def _get_payment_vals(self): res = super(HrExpenseRegisterPaymentWizard, self)._get_payment_vals() diff --git a/addons/l10n_in_hr_payroll/report/report_payroll_advice.py b/addons/l10n_in_hr_payroll/report/report_payroll_advice.py index 1a68c2d58f5..e72e95f0683 100644 --- a/addons/l10n_in_hr_payroll/report/report_payroll_advice.py +++ b/addons/l10n_in_hr_payroll/report/report_payroll_advice.py @@ -4,7 +4,6 @@ import time from datetime import datetime -from odoo.tools import amount_to_text_en from odoo import api, models @@ -23,9 +22,6 @@ class payroll_advice_report(models.AbstractModel): res['to_name'] = to_date.strftime('%d') + '-' + to_date.strftime('%B') + '-' + to_date.strftime('%Y') return res - def convert(self, amount, cur): - return amount_to_text_en.amount_to_text(amount, 'en', cur) - def get_bysal_total(self): return self.total_bysal @@ -55,7 +51,6 @@ class payroll_advice_report(models.AbstractModel): 'docs': advice, 'time': time, 'get_month': self.get_month, - 'convert': self.convert, 'get_detail': self.get_detail, 'get_bysal_total': self.get_bysal_total, } diff --git a/odoo/addons/base/res/res_currency.py b/odoo/addons/base/res/res_currency.py index 259567b7313..fbb5fac2aaa 100644 --- a/odoo/addons/base/res/res_currency.py +++ b/odoo/addons/base/res/res_currency.py @@ -2,10 +2,17 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import json +import logging import math import re import time +try: + from num2words import num2words +except ImportError: + logging.getLogger(__name__).warning("The num2words python library is not installed, l10n_mx_edi features won't be fully available.") + num2words = None + from odoo import api, fields, models, tools, _ CURRENCY_DISPLAY_PATTERN = re.compile(r'(\w+)\s*(?:\((.*)\))?') @@ -28,6 +35,8 @@ class Currency(models.Model): position = fields.Selection([('after', 'After Amount'), ('before', 'Before Amount')], default='after', string='Symbol Position', help="Determines where the currency symbol should be placed after or before the amount.") date = fields.Date(compute='_compute_date') + currency_unit_label = fields.Char(string="Currency Unit", help="Currency Unit Name") + currency_subunit_label = fields.Char(string="Currency Subunit", help="Currency Subunit Name") _sql_constraints = [ ('unique_name', 'unique (name)', 'The currency code must be unique!'), @@ -79,6 +88,34 @@ class Currency(models.Model): def name_get(self): return [(currency.id, tools.ustr(currency.name)) for currency in self] + @api.multi + def amount_to_text(self, amount): + self.ensure_one() + def _num2words(number, lang): + try: + return num2words(number, lang=lang).title() + except NotImplementedError: + return num2words(number, lang='en').title() + + if num2words is None: + logging.getLogger(__name__).warning("The library 'num2words' is missing, cannot render textual amounts.") + return "" + + fractional_value, integer_value = math.modf(amount) + fractional_amount = round(abs(fractional_value), self.decimal_places) * (math.pow(10, self.decimal_places)) + lang_code = self.env.context.get('lang') or self.env.user.lang + lang = self.env['res.lang'].search([('code', '=', lang_code)]) + amount_words = tools.ustr('{amt_value} {amt_word}').format( + amt_value=_num2words(int(integer_value), lang=lang.iso_code), + amt_word=self.currency_unit_label, + ) + if not self.is_zero(fractional_value): + amount_words += ' ' + _('and') + tools.ustr(' {amt_value} {amt_word}').format( + amt_value=_num2words(int(fractional_amount), lang=lang.iso_code), + amt_word=self.currency_subunit_label, + ) + return amount_words + @api.multi def round(self, amount): """Return ``amount`` rounded according to ``self``'s rounding rules. diff --git a/odoo/addons/base/res/res_currency_data.xml b/odoo/addons/base/res/res_currency_data.xml index 22478fbcfa2..ee793d3f25d 100644 --- a/odoo/addons/base/res/res_currency_data.xml +++ b/odoo/addons/base/res/res_currency_data.xml @@ -7,6 +7,8 @@ $ 0.01 before + Dollars + Cents @@ -14,6 +16,8 @@ Bs.F 0.0001 + Bolivar + Centimos @@ -21,6 +25,8 @@ $ 0.01 + Dollars + Cents @@ -28,6 +34,8 @@ CHF 0.01 + Franc + Centimes @@ -36,6 +44,8 @@ 0.01 before + Real + Centavos @@ -43,6 +53,8 @@ ¥ 0.01 + Yuan + Fen @@ -51,6 +63,8 @@ 0.01 before + Peso + Centavos @@ -58,6 +72,8 @@ Kč 0.01 + Koruna + Halers @@ -66,6 +82,8 @@ 0.01 before + Krone + Ore @@ -73,6 +91,8 @@ Ft 1.00 + Forint + Filler @@ -80,6 +100,8 @@ Rp 0.01 + Rupiah + Sen @@ -87,6 +109,8 @@ Ls 0.01 + Lats + Santims @@ -95,6 +119,8 @@ 0.01 before + Krone + Ore @@ -102,6 +128,8 @@ XPF 1.00 + Franc + Centimes @@ -109,6 +137,8 @@ B/. 0.01 + Balboa + Centesimo @@ -116,6 +146,8 @@ zł 0.01 + Zloty + Groszy @@ -123,6 +155,8 @@ kr 0.01 + Krona + Ore @@ -130,6 +164,8 @@ $ 0.01 + Peso + Centavos @@ -137,6 +173,8 @@ ₹ 0.01 + Rupees + Paise @@ -145,6 +183,8 @@ before 0.01 + Dollars + Cents @@ -152,6 +192,8 @@ ₴ 0.01 + Hryvnia + Kopiyka @@ -159,6 +201,8 @@ ₫ 0.01 + Dong + Xu @@ -166,6 +210,8 @@ $ 0.01 + Dollars + Cents @@ -173,6 +219,8 @@ ¥ 0.01 + Yen + Cen @@ -180,6 +228,8 @@ лв 0.01 + Lev + Stotinki @@ -187,6 +237,8 @@ Lt 0.01 + Litas + Centas @@ -194,6 +246,8 @@ lei 0.01 + Leu + Bani @@ -201,6 +255,8 @@ kn 0.01 + Kuna + Lipa @@ -208,6 +264,8 @@ руб 0.01 + Ruble + Kopek @@ -215,6 +273,8 @@ ₺ 0.01 + Lira + Kurus @@ -222,6 +282,8 @@ ₩ 0.01 + Won + Chon @@ -230,6 +292,8 @@ 0.01 before + Pesos + Centavos @@ -237,6 +301,8 @@ RM 0.01 + Ringgit + Sen @@ -245,6 +311,8 @@ before 0.01 + Dollars + Cents @@ -252,6 +320,8 @@ Php 0.01 + Peso + Centavos @@ -259,6 +329,8 @@ $ 0.01 + Dollars + Cents @@ -266,6 +338,8 @@ R 0.01 + Rand + Cents @@ -278,6 +352,8 @@ 0.01 ¢ + Colon + Centimos @@ -285,6 +361,8 @@ Rs 0.01 + Rupee + Cents @@ -292,6 +370,8 @@ CFA 1 + Franc + Centimes @@ -299,6 +379,8 @@ FCFA 1 + Franc + Centimes @@ -306,6 +388,8 @@ USh 1 + Shilling + Cents @@ -313,6 +397,8 @@ L 0.01 + Lempira + Centavos @@ -320,6 +406,8 @@ $ 0.01 + Peso + Centavos @@ -327,6 +415,8 @@ $ 0.01 + Peso + Centesimos @@ -334,6 +424,8 @@ Afs 0.01 + Afghani + Puls @@ -341,6 +433,8 @@ Kz 0.01 + Kwanza + Centimos @@ -348,6 +442,8 @@ $ 0.01 + Dollars + Cents @@ -355,6 +451,8 @@ դր. 0.01 + Dram + Luma @@ -362,6 +460,8 @@ Afl. 0.01 + Guilder + Cents @@ -369,6 +469,8 @@ m 0.01 + Manat + Qapik @@ -376,6 +478,8 @@ B$ 0.01 + Dollars + Cents @@ -383,6 +487,8 @@ BD 0.01 + Dinar + Fils @@ -390,6 +496,8 @@ ৳ 0.01 + Taka + Paisa @@ -397,6 +505,8 @@ Bds$ 0.01 + Dollars + Cents @@ -404,6 +514,8 @@ BR 0.01 + Ruble + Kapeyka @@ -411,6 +523,8 @@ BZ$ 0.01 + Dollars + Cents @@ -418,6 +532,8 @@ BD$ 0.01 + Dollars + Cents @@ -425,6 +541,8 @@ Nu. 0.01 + Ngultrum + Chhertum @@ -432,6 +550,8 @@ Bs. 0.01 + Boliviano + Centavos @@ -439,6 +559,8 @@ KM 0.01 + Mark + Fening @@ -446,6 +568,8 @@ P 0.01 + Pula + Thebe @@ -453,6 +577,8 @@ FBu 0.01 + Franc + Centime @@ -460,6 +586,8 @@ ៛ 0.01 + Riel + Sen @@ -467,6 +595,8 @@ $ 0.01 + Dollars + Cents @@ -474,6 +604,8 @@ CF 0.01 + Franc + Centime @@ -481,6 +613,8 @@ Fr 0.01 + Franc + Centime @@ -488,6 +622,8 @@ $ 0.01 + Peso + Centavos @@ -495,6 +631,8 @@ ƒ 0.01 + Guilder + Cents @@ -502,6 +640,8 @@ £ 0.01 + Euros + Cents @@ -509,6 +649,8 @@ Fdj 0.01 + Franc + Centime @@ -516,6 +658,8 @@ RD$ 0.01 + Peso + Centavos @@ -523,6 +667,8 @@ S/. 0.01 + Sucre + Centavos @@ -530,6 +676,8 @@ E£ 0.01 + Pound + Piastres @@ -537,6 +685,8 @@ ¢ 0.01 + Colones + Centavo @@ -544,6 +694,8 @@ Nfk 0.01 + Nakfa + Cents @@ -551,6 +703,8 @@ Br 0.01 + Birr + Cents @@ -558,6 +712,8 @@ £ 0.01 + Pound + Penny @@ -565,6 +721,8 @@ FJ$ 0.01 + Dollars + Cents @@ -572,6 +730,8 @@ ლ 0.01 + Lari + Tetri @@ -579,6 +739,8 @@ £ 0.01 + Pound + Penny @@ -586,6 +748,8 @@ Q 0.01 + Quetzales + Centavo @@ -593,6 +757,8 @@ FG 0.01 + Franc + Centime @@ -600,6 +766,8 @@ $ 0.01 + Dollars + Cents @@ -607,6 +775,8 @@ G 0.01 + Gourde + Centime @@ -614,6 +784,8 @@ kr 0.01 + Krona + Aurar @@ -621,6 +793,8 @@ ﷼ 0.01 + Dinar + Fils @@ -628,6 +802,8 @@ ع.د 0.01 + Dinar + Fils @@ -635,6 +811,8 @@ ₪ 0.01 + Shekel + Agorot @@ -642,6 +820,8 @@ $ 0.01 + Dollars + Cents @@ -649,6 +829,8 @@ د.ا 0.01 + Dinar + Fils @@ -656,6 +838,8 @@ лв 0.01 + Tenge + Tiin @@ -663,6 +847,8 @@ KSh 0.01 + Shilling + Cents @@ -670,6 +856,8 @@ د.ك 0.01 + Dinar + Fils @@ -677,6 +865,8 @@ лв 0.01 + Som + Tyiyn @@ -684,6 +874,8 @@ ₭ 0.01 + Kip + Att @@ -691,6 +883,8 @@ ل.ل 0.01 + Pound + Piastres @@ -698,6 +892,8 @@ L 0.01 + Loti + Sente @@ -705,6 +901,8 @@ L$ 0.01 + Dollars + Cents @@ -712,6 +910,8 @@ ل.د 0.01 + Dinar + Centimes @@ -719,6 +919,8 @@ MOP$ 0.01 + Pataca + Sin @@ -726,6 +928,8 @@ ден 0.01 + Denar + Deni @@ -733,6 +937,8 @@ Ar 0.01 + Ariary + Iraimbilanja @@ -740,6 +946,8 @@ MK 0.01 + Kwacha + Tambala @@ -747,6 +955,8 @@ .ރ 0.01 + Rufiyaa + Laari @@ -754,6 +964,8 @@ UM 0.01 + Ouguiya + Khoums @@ -761,6 +973,8 @@ L 0.01 + Leu + Ban @@ -768,6 +982,8 @@ ₮ 0.01 + Tugrik + Mongo @@ -775,6 +991,8 @@ د.م. 0.01 + Dirham + Centimes @@ -782,6 +1000,8 @@ $ 0.01 + Dollars + Cents @@ -789,6 +1009,8 @@ DZ 0.01 + Dinar + Centimes @@ -796,6 +1018,8 @@ GH¢ 0.01 + Cedi + Pesewas @@ -803,6 +1027,8 @@ D 0.01 + Dalasi + Butut @@ -810,6 +1036,8 @@ Ƶ 0.01 + Zaire + Likuta @@ -817,6 +1045,8 @@ MT 0.01 + Metical + Centavo @@ -824,6 +1054,8 @@ K 0.01 + Kyat + Pya @@ -831,6 +1063,8 @@ $ 0.01 + Dollars + Cents @@ -838,6 +1072,8 @@ ₨ 0.01 + Rupee + Paisa @@ -845,6 +1081,8 @@ L 0.01 + Lek + Qindarke @@ -852,6 +1090,8 @@ C$ 0.01 + Cordoba + Centavos @@ -859,6 +1099,8 @@ ₦ 0.01 + Naira + Kobo @@ -866,6 +1108,8 @@ ₩ 0.01 + Won + Chon @@ -873,6 +1117,8 @@ Z$ 0.01 + Dollars + Cents @@ -880,6 +1126,8 @@ ZK 0.01 + Kwacha + Ngwee @@ -887,19 +1135,16 @@ ﷼ 0.01 - - - - VUB - Bs - 0.01 - + Rial + Fils EUR € 0.01 + Euros + Cents @@ -907,6 +1152,7 @@ VT 0.01 + Vatu @@ -914,6 +1160,8 @@ лв 0.01 + Som + Tiyin @@ -921,6 +1169,8 @@ د.إ 0.01 + Dirham + Fils @@ -928,6 +1178,8 @@ ₴ 0.01 + Hryvnia + Kopiyka @@ -935,6 +1187,8 @@ m 0.01 + Manat + Tenge @@ -942,6 +1196,8 @@ DT 0.01 + Dinar + Millimes @@ -949,6 +1205,8 @@ $ 0.01 + Dollars + Cents @@ -956,6 +1214,8 @@ T$ 0.01 + Paanga + Seniti @@ -963,6 +1223,8 @@ ฿ 0.01 + Baht + Satang @@ -970,6 +1232,8 @@ x/y 0.01 + Shilling + Senti @@ -977,6 +1241,8 @@ TJS 0.01 + Somoni + Diram @@ -984,6 +1250,8 @@ NT$ 0.01 + Dollars + Cents @@ -991,6 +1259,8 @@ £ 0.01 + Pound + Piastrp @@ -998,6 +1268,8 @@ E 0.01 + Lilangeni + Cents @@ -1005,6 +1277,8 @@ $ 0.01 + Dollars + Cents @@ -1012,6 +1286,8 @@ £Sd 0.01 + Dinar + Fils @@ -1019,6 +1295,8 @@ Rs 0.01 + Rupee + Cents @@ -1026,6 +1304,8 @@ £ 0.01 + Pounds + Piasters @@ -1034,6 +1314,8 @@ 0.01 before + Sterling + Penny @@ -1041,6 +1323,8 @@ Sh. 0.01 + Shillings + Senti @@ -1048,6 +1332,8 @@ SI$ 0.01 + Dollars + Cents @@ -1055,6 +1341,8 @@ Le 0.01 + Leone + Cents @@ -1062,6 +1350,8 @@ SR 0.01 + Rupee + Cents @@ -1069,6 +1359,8 @@ din. 0.01 + Dinar + Para @@ -1076,6 +1368,8 @@ SR 0.01 + Riyal + Halala @@ -1083,6 +1377,8 @@ Db 0.01 + Dobra + Centimo @@ -1090,6 +1386,8 @@ ₤ 0.01 + Lira + Centesimo @@ -1097,6 +1395,8 @@ WS$ 0.01 + Tala + Sene @@ -1104,6 +1404,8 @@ £ 0.01 + Pound + Penny @@ -1111,6 +1413,8 @@ RF 0.01 + Franc + Santime @@ -1118,6 +1422,8 @@ R 0.01 + Ruble + Kopek @@ -1125,13 +1431,16 @@ QR 0.01 + Rial + Dirham - PLZ zł 0.01 + Zloty + Grosz @@ -1140,6 +1449,8 @@ 0.01 before + Inti + Centimes @@ -1147,6 +1458,8 @@ ₲ 0.01 + Guarani + Centimos @@ -1154,6 +1467,8 @@ K 0.01 + Kina + Toea @@ -1161,6 +1476,8 @@ Rs. 0.01 + Rupee + Paisa @@ -1168,6 +1485,8 @@ ر.ع. 0.01 + Rial + Baisa @@ -1175,6 +1494,8 @@ $ 0.01 + Escudo + Centavo @@ -1182,6 +1503,8 @@ Sk 0.01 + Koruna + Halier @@ -1189,6 +1512,8 @@ дин. 0.01 + Dinar + Para @@ -1196,6 +1521,8 @@ Q 0.01 + Quetzal + Centavo diff --git a/odoo/addons/base/res/res_currency_demo.xml b/odoo/addons/base/res/res_currency_demo.xml index a6e406e783d..8ca63297a3d 100644 --- a/odoo/addons/base/res/res_currency_demo.xml +++ b/odoo/addons/base/res/res_currency_demo.xml @@ -763,12 +763,6 @@ 264.784483 - - - 2010-01-01 - 5.3821 - - 2010-01-01 diff --git a/odoo/addons/base/res/res_currency_view.xml b/odoo/addons/base/res/res_currency_view.xml index 8a2a33bc55c..5ff79cc2cdc 100644 --- a/odoo/addons/base/res/res_currency_view.xml +++ b/odoo/addons/base/res/res_currency_view.xml @@ -140,9 +140,15 @@ options='{"terminology": "active"}'/> - - - + + + + + + + + + diff --git a/odoo/tools/__init__.py b/odoo/tools/__init__.py index 3feb0940ff6..b2f2dc52253 100644 --- a/odoo/tools/__init__.py +++ b/odoo/tools/__init__.py @@ -11,8 +11,6 @@ from .convert import * from .translate import * from .graph import graph from .image import * -from .amount_to_text import * -from .amount_to_text_en import * from .yaml_import import * from .sql import * from .float_utils import * diff --git a/odoo/tools/amount_to_text.py b/odoo/tools/amount_to_text.py deleted file mode 100644 index bab608926f9..00000000000 --- a/odoo/tools/amount_to_text.py +++ /dev/null @@ -1,174 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -#------------------------------------------------------------- -# French -#------------------------------------------------------------- - - -from __future__ import print_function -to_19_fr = ( u'zéro', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', - 'sept', 'huit', 'neuf', 'dix', 'onze', 'douze', 'treize', - 'quatorze', 'quinze', 'seize', 'dix-sept', 'dix-huit', 'dix-neuf' ) -tens_fr = ( 'vingt', 'trente', 'quarante', 'Cinquante', 'Soixante', 'Soixante-dix', 'Quatre-vingts', 'Quatre-vingt Dix') -denom_fr = ( '', - 'Mille', 'Millions', 'Milliards', 'Billions', 'Quadrillions', - 'Quintillion', 'Sextillion', 'Septillion', 'Octillion', 'Nonillion', - 'Décillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion', - 'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Icosillion', 'Vigintillion' ) - -def _convert_nn_fr(val): - """ convert a value < 100 to French - """ - if val < 20: - return to_19_fr[val] - for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens_fr)): - base = 10 - if dval in [60, 80]: - base = 20 - if dval + base > val: - if val % base: - bond = (val % base in [1, 11] and dval != 80) and '-et-' or '-' - return dcap + bond + to_19_fr[val % base] - return dcap - -def _convert_nnn_fr(val): - """ convert a value < 1000 to french - - special cased because it is the level that kicks - off the < 100 special case. The rest are more general. This also allows you to - get strings in the form of 'forty-five hundred' if called directly. - """ - word = '' - (mod, rem) = (val % 100, val // 100) - if rem > 0: - word = (rem > 1 and to_19_fr[rem] + ' cents') or 'Cent' - if mod > 0: - word += ' ' - if mod > 0: - word += _convert_nn_fr(mod) - return word - -def french_number(val): - if val < 100: - return _convert_nn_fr(val) - if val < 1000: - return _convert_nnn_fr(val) - for (didx, dval) in ((v - 1, 1000 ** v) for v in range(len(denom_fr))): - if dval > val: - mod = 1000 ** didx - l = val // mod - r = val - (l * mod) - ret = _convert_nnn_fr(l) + ' ' + denom_fr[didx] - if r > 0: - ret = ret + ', ' + french_number(r) - return ret - -def amount_to_text_fr(number, currency): - number = '%.2f' % number - units_name = currency - list = str(number).split('.') - start_word = french_number(abs(int(list[0]))) - end_word = french_number(int(list[1])) - cents_number = int(list[1]) - cents_name = (cents_number > 1) and ' Cents' or ' Cent' - final_result = start_word +' '+units_name+' '+ end_word +' '+cents_name - return final_result - -#------------------------------------------------------------- -# Dutch -#------------------------------------------------------------- - -to_19_nl = ( 'Nul', 'Een', 'Twee', 'Drie', 'Vier', 'Vijf', 'Zes', - 'Zeven', 'Acht', 'Negen', 'Tien', 'Elf', 'Twaalf', 'Dertien', - 'Veertien', 'Vijftien', 'Zestien', 'Zeventien', 'Achttien', 'Negentien' ) -tens_nl = ( 'Twintig', 'Dertig', 'Veertig', 'Vijftig', 'Zestig', 'Zeventig', 'Tachtig', 'Negentig') -denom_nl = ( '', - 'Duizend', 'Miljoen', 'Miljard', 'Triljoen', 'Quadriljoen', - 'Quintillion', 'Sextiljoen', 'Septillion', 'Octillion', 'Nonillion', - 'Decillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion', - 'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Novemdecillion', 'Vigintillion' ) - -def _convert_nn_nl(val): - """ convert a value < 100 to Dutch - """ - if val < 20: - return to_19_nl[val] - for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens_nl)): - if dval + 10 > val: - if val % 10: - return to_19_nl[val % 10] + '-en-' + dcap - return dcap - -def _convert_nnn_nl(val): - """ convert a value < 1000 to Dutch - - special cased because it is the level that kicks - off the < 100 special case. The rest are more general. This also allows you to - get strings in the form of 'forty-five hundred' if called directly. - """ - word = '' - (mod, rem) = (val % 100, val // 100) - if rem > 0: - word = (rem > 1 and to_19_nl[rem] + 'honderd') or 'Honderd' - if mod > 0: - word += ' ' - if mod > 0: - word += _convert_nn_nl(mod) - return word - -def dutch_number(val): - if val < 100: - return _convert_nn_nl(val) - if val < 1000: - return _convert_nnn_nl(val) - for (didx, dval) in ((v - 1, 1000 ** v) for v in range(len(denom_nl))): - if dval > val: - mod = 1000 ** didx - l = val // mod - r = val - (l * mod) - ret = _convert_nnn_nl(l) + ' ' + denom_nl[didx] - if r > 0: - ret = ret + ', ' + dutch_number(r) - return ret - -def amount_to_text_nl(number, currency): - number = '%.2f' % number - units_name = currency - list = str(number).split('.') - start_word = dutch_number(int(list[0])) - end_word = dutch_number(int(list[1])) - cents_number = int(list[1]) - cents_name = (cents_number > 1) and 'cent' or 'cent' - final_result = start_word +' '+units_name+' '+ end_word +' '+cents_name - return final_result - -#------------------------------------------------------------- -# Generic functions -#------------------------------------------------------------- - -_translate_funcs = {'fr' : amount_to_text_fr, 'nl' : amount_to_text_nl} - -def add_amount_to_text_function(lang, func): - _translate_funcs[lang] = func - -#TODO: we should use the country AND language (ex: septante VS soixante dix) -#TODO: we should use en by default, but the translation func is yet to be implemented -def amount_to_text(nbr, lang='fr', currency='euro'): - """ Converts an integer to its textual representation, using the language set in the context if any. - - Example:: - - 1654: mille six cent cinquante-quatre. - """ -# if nbr > 1000000: -##TODO: use logger -# print "WARNING: number too large '%d', can't translate it!" % (nbr,) -# return str(nbr) - - if lang not in _translate_funcs: -#TODO: use logger - print("WARNING: no translation function found for lang: '%s'" % (lang,)) -#TODO: (default should be en) same as above - lang = 'fr' - return _translate_funcs[lang](abs(nbr), currency) diff --git a/odoo/tools/amount_to_text_en.py b/odoo/tools/amount_to_text_en.py deleted file mode 100644 index b1854b1c4d6..00000000000 --- a/odoo/tools/amount_to_text_en.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -import logging -from .translate import _ - -_logger = logging.getLogger(__name__) - -#------------------------------------------------------------- -#ENGLISH -#------------------------------------------------------------- - -to_19 = ( 'Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', - 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', - 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' ) -tens = ( 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety') -denom = ( '', - 'Thousand', 'Million', 'Billion', 'Trillion', 'Quadrillion', - 'Quintillion', 'Sextillion', 'Septillion', 'Octillion', 'Nonillion', - 'Decillion', 'Undecillion', 'Duodecillion', 'Tredecillion', 'Quattuordecillion', - 'Sexdecillion', 'Septendecillion', 'Octodecillion', 'Novemdecillion', 'Vigintillion' ) - -def _convert_nn(val): - """convert a value < 100 to English. - """ - if val < 20: - return to_19[val] - for (dcap, dval) in ((k, 20 + (10 * v)) for (v, k) in enumerate(tens)): - if dval + 10 > val: - if val % 10: - return dcap + '-' + to_19[val % 10] - return dcap - -def _convert_nnn(val): - """ - convert a value < 1000 to english, special cased because it is the level that kicks - off the < 100 special case. The rest are more general. This also allows you to - get strings in the form of 'forty-five hundred' if called directly. - """ - word = '' - (mod, rem) = (val % 100, val // 100) - if rem > 0: - word = to_19[rem] + ' Hundred' - if mod > 0: - word += ' ' - if mod > 0: - word += _convert_nn(mod) - return word - -def english_number(val): - if val < 100: - return _convert_nn(val) - if val < 1000: - return _convert_nnn(val) - for (didx, dval) in ((v - 1, 1000 ** v) for v in range(len(denom))): - if dval > val: - mod = 1000 ** didx - l = val // mod - r = val - (l * mod) - ret = _convert_nnn(l) + ' ' + denom[didx] - if r > 0: - ret = ret + ', ' + english_number(r) - return ret - -def amount_to_text(number, currency): - number = '%.2f' % number - units_name = currency - list = str(number).split('.') - start_word = english_number(int(list[0])) - end_word = english_number(int(list[1])) - cents_number = int(list[1]) - cents_name = (cents_number > 1) and 'Cents' or 'Cent' - - return ' '.join(w for w in [start_word, units_name, (start_word or units_name) and (end_word or cents_name) and 'and', end_word, cents_name] if w) - - -#------------------------------------------------------------- -# Generic functions -#------------------------------------------------------------- - -_translate_funcs = {'en' : amount_to_text} - -#TODO: we should use the country AND language (ex: septante VS soixante dix) -#TODO: we should use en by default, but the translation func is yet to be implemented -def amount_to_text(nbr, lang='en', currency='euro'): - """ Converts an integer to its textual representation, using the language set in the context if any. - - Example:: - - 1654: thousands six cent cinquante-quatre. - """ - if lang not in _translate_funcs: - _logger.warning(_("no translation function found for lang: '%s'"), lang) - #TODO: (default should be en) same as above - lang = 'en' - return _translate_funcs[lang](abs(nbr), currency)