如何将数字转换为odoo中的单词?
How to convert numbers to words in odoo?
在发票中,我想将总金额转换为印度编号系统中的单词(百、千、十万、千万)。我无法使用 amount_to_text 库模块,因为它已设置为欧元货币。那么如何在python中写函数来实现呢? (不要担心缩进,它在我的系统中是正确的)当我在我的自定义模块中尝试这段代码时,我得到了这个错误
TypeError: _int2word() 正好接受 1 个参数(给定 7 个)
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 那么它将不仅仅是欧元它会 return 您传递给它的任何货币。
在发票中,我想将总金额转换为印度编号系统中的单词(百、千、十万、千万)。我无法使用 amount_to_text 库模块,因为它已设置为欧元货币。那么如何在python中写函数来实现呢? (不要担心缩进,它在我的系统中是正确的)当我在我的自定义模块中尝试这段代码时,我得到了这个错误 TypeError: _int2word() 正好接受 1 个参数(给定 7 个)
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 那么它将不仅仅是欧元它会 return 您传递给它的任何货币。