Skip to Content
Menu
This question has been flagged
11 Replies
23531 Views

I want to convert amount_total in invoice to words in Indian rupees. I tried like this,

In .py file,

class account_invoice(models.Model): 
_inherit = "account.invoice"
@api.multi
def amount_to_text(self, amount, currency='rupee'):
    return amount_to_text(amount, currency)

In report,

 <strong><td>Total in words:</td></strong> 
<span t-esc="o.amount_to_text(o.amount_total, o.currency_id)"/>

But still it is coming in euros

Avatar
Discard
Best Answer

I recommend to use num2words library:

https://pypi.python.org/pypi/num2words

Here is an example using it with Spanish and it supports indian too.

from num2words import num2words
pre = float(value)
text = ''
entire_num = int((str(pre).split('.'))[0])
decimal_num = int((str(pre).split('.'))[1])
if decimal_num < 10:
decimal_num = decimal_num * 10
text+=num2words(entire_num, lang='es')
text+=' con '
text+=num2words(decimal_num, lang='es')
print text

You can use it directly like:

text = num2words(value, lang='en_IN')

But the first example provides a better monetary approach


Avatar
Discard
Author

thanks

Author

Hey if i try this on python IDE it works perfectly but on odoo report it comes blankclass account_invoice(models.Model): _inherit = "account.invoice" @api.one def _print_amount(self): print "Hello world" value=self.amount_total print value pre = float(value) text1 = '' text2 = '' result = '' entire_num = int((str(pre).split('.'))[0]) decimal_num = int((str(pre).split('.'))[1]) if decimal_num

Best Answer

Hello my friend;

1.here is how you can convert your amount_total to the available currency:

import urllib2

import json

def currencyConverter(currency_from,currency_to,currency_input):

yql_base_url = "https://query.yahooapis.com/v1/public/yql"

yql_query = 'select * from yahoo.finance.xchange where pair in ("'+currency_from+currency_to+'")'

yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"

try:

yql_response = urllib2.urlopen(yql_query_url)

try:

yql_json = json.loads(yql_response.read())

currency_output = currency_input * float(yql_json['query']['results']['rate']['Rate'])

return currency_output

except (ValueError, KeyError, TypeError):

return "JSON format error"

except IOError, e:

if hasattr(e, 'code'):

return e.code

elif hasattr(e, 'reason'):

return e.reason

###### in the currency_input you will put your amount_total that you have got in euros###

currency_input = 1

currency_from = "EUR" # currency codes : http://en.wikipedia.org/wiki/ISO_4217

currency_to = "INR"

rate = currencyConverter(currency_from,currency_to,currency_input)

print rate

2.And then to have the amount_total in word you will use this:

Use pynum2word module that can be found at sourceforge
>>> import num2word
>>> num2word.to_card(15)
'fifteen'
>>> num2word.to_card(55)
'fifty-five'
>>> num2word.to_card(1555)

'one thousand, five hundred and fifty-five'

here is a useful link to this part:

http://stackoverflow.com/questions/8982163/how-do-i-tell-python-to-convert-integers-into-words

Best regards.

Avatar
Discard
Author

Hey,thanks for the answer but i used answer provided by Dress as it as very simpler

Author

Hey,thanks for the answer but i used answer provided by Axel as it as very simpler

Author

i don't have enough karma to edit comments

Best Answer

hi , i had download module 'pynum2word' but it isnt working for me

please tell me how to use it i want to convert number to letters how to integrate it in my module

thanks

Avatar
Discard
Best Answer

Hi,

Kindly check these .py files: amount_to_text_en, amount_to_text 

Edit:

You can also check this questions

Regards

Avatar
Discard
Author

I want in rupees, but if i use this i will get in euros

I edited my answer, If this not helped you please add more details to your question ...

Related Posts Replies Views Activity
1
Feb 16
2856
1
Apr 20
1992
1
Dec 16
3820
6
Aug 16
26817
1
Jul 16
3927