This question has been flagged
3 Replies
3354 Views

Hi community,

I try to use on_change method (Odoo 9c) to change a field value on the same view, code as follow:

class xyz(models.Model):

   ....

    'qty' : fields.integer('Qty'),

    'buff_qty': fields.integer('Buffer Qty'),

    ....

    def on_change_qty(self, cr, uid, ids, qty, context=None):

        return {'value': {'buf_qty': qty}}


on view :

    <field name="arch" type="xml">

             <field name="qty" on_change="on_change_qty(qty)" />



The code and view loaded without error but when I changed the qty field nothing happend.  I did see a "loading' text shown up on top of the form for a while , but buf_qty don't change the value as on_change defined.


I tried the @api.onchange & remove the on_change from view , code as follow


@api.onchange('probability')

def  set_buff_qty(self):

    self.buff_qty = self.qty 


still no luck .... :(


Any thing I missed?


Thank you Community :D 


Avatar
Discard
Best Answer

dear Prihadi Ramadhany,


i think you must replace this code :

@api.onchange('probability')

def  set_buff_qty(self):

    self.buff_qty = self.qty 

by:


@api.multi

@api.onchange('qty')

def  set_buff_qty(self):

    self.buff_qty = self.qty 


I hope I helped you...


Avatar
Discard
Author

Hi Ayman,

Please forgive me the type...the original code its @api.onchange('qty') , I solved the problem....please see my own reply

Thank you for you reply and attention :D

Author Best Answer

Ok,


its works now....the code modified as follow:

    def on_change_qty(self, cr, uid, ids, qty, buff_qty, context=None):

        return {'value': {'buff_qty': qty}}


and on view

     <field name="arch" type="xml">

             <field name="qty" on_change="on_change_qty(qty,buff_qty)" />


and its works ..... :D  still wonder why I need to sent both parameter and cant use self.buff_qty to refer to buff_qty on the view.



Avatar
Discard