Odoo Help

1

functional fields in openerp - convert amount to word string

By
nishad
on 7/14/13, 3:48 AM 2,875 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

View:

<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

1
nazarii
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.

nishad
on 7/14/13, 6:19 AM

Please, mark this answer as correct if it works.

nazarii
on 7/14/13, 6:26 AM

1 answer :

nishad
on 7/14/13, 6:34 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

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