2015-11-07 36 views
0

在發票中,我想將總金額轉換爲印度編號系統中的單詞(數百,千,百萬,千分之一)。我不能使用amount_to_text庫模塊,因爲它已經設置爲歐元貨幣。那麼如何在python中編寫函數來實現呢? (不要擔心ABT indendation,其正確的在我的系統),當我在我的自定義模塊嘗試這種代碼,我得到這個錯誤 類型錯誤:_int2word()恰恰1個參數(7給出)如何將數字轉換爲odoo中的單詞?

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"), 
} 

回答

1

你可以使用amount_to_text_en函數從openerp.tools這個函數需要3個參數the_value,the_partner.lang和currency_name,那麼它不會只是歐元,它會返回任何你傳遞給它的貨幣。

+0

這是我應該如何傳球,amount_to_text(amount_total,EN,INR) – Bhanukiran

+0

沒錯這裏INR是CURRENCY_NAME :) –

+0

它沒有工作,但修改amount_to_text它現在 – Bhanukiran