Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
4057 Näkymät

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?

Avatar
Hylkää
Paras vastaus

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 } 

Avatar
Hylkää
Paras vastaus

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.

Avatar
Hylkää
Tekijä

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

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

Paras vastaus

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

Avatar
Hylkää
Tekijä

Already i did like this

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