Skip to Content
Menu
This question has been flagged
2 Replies
6778 Views

I have a field "n_total" which stores the total value.

I want to convert this float value into words as an INR (Indian Rupee) in another field "w_amount".

So I write a function to get the total amount in words.

My function is:

def _amount_in_words(self, cr, uid, ids, field_name, arg, context=None):

cur_obj = self.pool.get('res.currency')

res = {}

for words in self.browse(cr, uid, ids, context=context):

res[words.id] = amount_to_text_en.amount_to_text(float(words.n_total),cur_obj)

return res

The  field is

'w_amount':fields.function(_amount_in_words, string='In Words', type="char", store=True, help="The amount in words"),

The field show in words but it is in Euro.

For example the words are shown like this

Five Thousand, One Hundred Ninety-Two euro and Thirty-One Cents

I want to show this is in INR

How can I achieve this?

My second doubt is I want to add the text Only at the end of the the words. How can I do this?

Thanks.

Avatar
Discard
Best Answer

Hi,

For the first part: as here you can pass the currency string so you can do something like:

res[words.id] = amount_to_text_en.amount_to_text(float(words.n_total),currency="INT")

this will override the default 'euro' string.

For the second part, I didn't got it ...

Update:

if you don't like the ' and Zero Cent' part and you always do rounding off, you can simply replace it as a quick workaround as:

res[words.id] = amount_to_text_en.amount_to_text(float(words.n_total),currency="INT").replace(' and Zero Cent', '')

Hope this could helps ....

Avatar
Discard
Author

Thanks for your reply but it gives output as

"Five Thousand, One Hundred Ninety-Two INR and Zero Cent"

I have round off the field value and I does not need the decimal value which is shows in cent.

Best Answer
dear Uppili Arivukkannu
I think you need to round the amount lke this 
round(your_amount,Precision)
amount 5.25 Precision  round(5.25, 1)  result is 5.3
Avatar
Discard
Related Posts Replies Views Activity
0
Apr 20
2061
2
May 15
3597
0
Dec 16
2726
1
Apr 24
326
2
Jan 24
535