Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to convert number to word in oddo?

By
bhanukiran
on 11/14/15, 2:41 AM 1,575 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

1

Axel Mendoza

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 11/15/15, 8:02 AM

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


thanks

bhanukiran
on 11/16/15, 1:58 AM

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

bhanukiran
on 11/16/15, 6:40 AM
2

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 11/15/15, 3:01 PM

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.

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

bhanukiran
on 11/16/15, 1:59 AM

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

bhanukiran
on 11/16/15, 2:01 AM

i don't have enough karma to edit comments

bhanukiran
on 11/16/15, 2:01 AM
0
B.hind
On 9/5/16, 11:53 AM

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

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 11/14/15, 5:15 AM

Hi,

Kindly check these .py files: amount_to_text_en, amount_to_text 

Edit:

You can also check this questions

Regards

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

bhanukiran
on 11/14/15, 5:59 AM

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

Ahmed M.Elmubarak
on 11/14/15, 6:08 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 11/14/15, 2:41 AM
Seen: 1575 times
Last updated: 9/5/16, 11:53 AM