如何在odoo中将数字转换为单词? [英] How to convert numbers to words in odoo?
问题描述
在发票中,我想将总额转换为印度编号系统中的字(数百,数千,十万,十万).我无法使用amount_to_text库模块,因为它已设置为欧元.那么如何在python中编写函数来实现这一点呢? (不要担心,它在我的系统中是正确的)当我在自定义模块中尝试此代码时,出现此错误 TypeError:_int2word()恰好接受1个参数(给定7个参数)
In the invoice, I want to convert total amount to words in Indian numbering system(hundreds, thousands, lakhs, crores). I cant use amount_to_text library module since it has been set in euro currency. So how to write function in python to achieve this? (dont worry abt indendation,its correct in my system) When i tried this code in my custom module, i get this error TypeError: _int2word() takes exactly 1 argument (7 given)
class account_invoice(models.Model):
_inherit = "account.invoice"
print "hello"
ones = ["", "one ","two ","three ","four ", "five ", "six ","seven ","eight ","nine "]
tens = ["ten ","eleven ","twelve ","thirteen ", "fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]
twenties = ["","","twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety "]
thousands = ["","thousand ","lakh ", "crore "]
def _int2word(amount_total):
n = amount_total
n3 = []
r1 = ""
ns = str(n)
for k in range(3, 33, 3):
r = ns[-k:]
q = len(ns) - k
if q < -2:
break
else:
if q >= 0:
n3.append(int(r[:3]))
elif q >= -1:
n3.append(int(r[:2]))
elif q >= -2:
n3.append(int(r[:1]))
r1 = r
nw = ""
for i, x in enumerate(n3):
b1 = x % 10
b2 = (x % 100)//10
b3 = (x % 1000)//100
#print b1, b2, b3 # test
if x == 0:
continue # skip
else:
t = thousands[i]
if b2 == 0:
nw = ones[b1] + t + nw
elif b2 == 1:
nw = tens[b1] + t + nw
elif b2 > 1:
nw = twenties[b2] + ones[b1] + t + nw
if b3 > 0:
nw = ones[b3] + "hundred " + nw
return nw
_columns = {
'amount_words': fields.function(_int2word, string='In Words', type="char"),
}
推荐答案
您可以使用openerp.tools
中的amount_to_text_en
函数,该函数接受3个参数the_value,the_partner.lang和currency_name,它将不仅是欧元,还将是返回您传递给它的任何货币.
You could use amount_to_text_en
function from openerp.tools
this function takes 3 parameters the_value , the_partner.lang and the currency_name then it will be not just Euro it will return any currency you pass to it.
这篇关于如何在odoo中将数字转换为单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!