コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6847 ビュー

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

アバター
破棄
最善の回答

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.

Please, mark this answer as correct if it works.

著作者

1 answer :