Odoo Help


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.


functional fields in openerp - convert amount to word string

on 7/14/13, 3:48 AM 2,147 views

I would like to know how can we convert an amount in to equivalent amount string in opnerp7. I defined a functional field to achieve this but its creating a field in my DataBase but not the data , can anyone please point out where am i wrong, I can post my sample source here


<field name="amount_words"/>

python code

function that returns converted amount -

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

    cur_obj = self.pool.get('res.currency')
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
        taxed = untaxed = 0.0
        res[order.id] = {
            'amount_words': '0.0',
        val = val1 = 0.0
        cur = order.pricelist_id.currency_id
        for line in order.order_line:
            val1 += line.price_subtotal
            val += self._amount_line_tax(cr, uid, line, context=context)

        taxed = cur_obj.round(cr, uid, cur, val)
        untaxed = cur_obj.round(cr, uid, cur, val1)

        res[order.id]['amount_words'] = amount_to_text(float(taxed + untaxed))

    return res[order.id]['amount_words']

functional field declaration

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

Note :- 'amount_to_text' is a my applications global function that is giving exactly what i want but i could't pass the same data in to my view ???

'amount_to_text' returns data like as follows , if i pass amount_to_text(150) it returns One Hundred and Fifty rupees Only

Any help is appreciated .... Thanks in advance

On 7/14/13, 5:57 AM

It seems to me you are returning the wrong value, functional field without multi defined needs to return dictionary, where keys are records ids and values are computed record values, so accordingly to your code the last two lines of code should looks like:

    res[order.id] = amount_to_text(float(taxed + untaxed))

return res

Thanks nazarii .....it works.....:) , Thanks for pointing out 'multi' option in functional field.

on 7/14/13, 6:19 AM

Please, mark this answer as correct if it works.

on 7/14/13, 6:26 AM

1 answer :

on 7/14/13, 6:34 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

0 follower(s)


Asked: 7/14/13, 3:48 AM
Seen: 2147 times
Last updated: 6/4/15, 5:28 AM