Odoo Help

Welcome!

This community 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.

0

On change method wont work

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


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

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...


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
0
Prihadi Ramadhany
On 9/8/16, 1:10 AM

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.



Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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