Odoo Help


On change method wont work

Prihadi Ramadhany
on 9/6/16, 2:09 PM 845 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


def  set_buff_qty(self):

    self.buff_qty = self.qty 

still no luck .... :(

Any thing I missed?

Thank you Community :D 

ayman mohammed adam
On 9/7/16, 3:09 AM

dear Prihadi Ramadhany,

i think you must replace this code :


def  set_buff_qty(self):

    self.buff_qty = self.qty 




def  set_buff_qty(self):

    self.buff_qty = self.qty 

I hope I helped you...

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

Prihadi Ramadhany
on 9/8/16, 1:07 AM
Prihadi Ramadhany
On 9/8/16, 1:10 AM


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.

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.


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)


Asked: 9/6/16, 2:09 PM
Seen: 845 times
Last updated: 10/17/16, 9:35 AM