Odoo Help

0

on_change function on a float field

By
aci aisha
on 3/10/15, 5:18 AM 1,055 views

I have a float field total_qty.

I want to change another 4 quantities when this field changes.

So i create an on_change function as follows..

in .xml,

                    <field name="total_qty" on_change="onchange_total_qty(total_qty)"/>

in .py,

        def onchange_total_qty(self,cr,uid,ids,total_qty,context=None):
        vals = {'ratio_codes': '','r38ids': '','r40ids': '','r42ids': '','r44ids': ''}
        if total_qty:
            sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None)
            vals['ratio_codes'] = sample2.ratio_code
            vals['r38ids'] = sample2.r38 * total_qty
            vals['r40ids'] = sample2.r40 * total_qty
            vals['r42ids'] = sample2.r42 * total_qty
            vals['r44ids'] = sample2.r44 * total_qty
        return {'value' : vals } 

But when i execute the following error occured!!

       TypeError: 'float' object is not iterable

What should be the mistake?

1
Vasanth
On 3/10/15, 5:58 AM

H,

you can just change your code like this:

def onchange_total_qty(self,cr,uid,ids,total_qty,context=None):
        vals = {'ratio_codes': '','r38ids': '','r40ids': '','r42ids': '','r44ids': ''}
        if total_qty:
            sample2=self.pool.get('ratio').browse(cr, uid, ids, context=None)
            vals['ratio_codes'] = sample2.ratio_code
            vals['r38ids'] = sample2.r38 * total_qty
            vals['r40ids'] = sample2.r40 * total_qty
            vals['r42ids'] = sample2.r42 * total_qty
            vals['r44ids'] = sample2.r44 * total_qty
        return {'value' : vals } 

0
Temur
On 3/10/15, 5:22 AM

sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None) << ERROR: total_qty passed instead of ids.

Already i did like this

aci aisha
on 3/10/15, 5:35 AM

yes I see, but your question was: "What should be the mistake?" so I highlighted the mistake

Temur
on 3/10/15, 6:05 AM
0

Hi,

I think you have make something wrong as follows.

if total_qty:
            #sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None) this is wrong.

          sample2=self.pool.get('ratio').browse(cr, uid, ids[0], context=None)
            vals['ratio_codes'] = sample2.ratio_code

In the browse method you can not pass "total_qty" in place of "ids[0]". So, just change it and make your code will running.

Whats wrong..I coded as u..Where i pass ids?

aci aisha
on 3/10/15, 5:37 AM

I have just update my answer. Please have a look on it.

Emipro Technologies Pvt. Ltd.
on 3/10/15, 6:06 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

1 follower(s)

Stats

Asked: 3/10/15, 5:18 AM
Seen: 1055 times
Last updated: 3/16/15, 8:10 AM