Odoo Help


on_change in xml in odoo

on 7/13/16, 7:17 AM 745 views

how to pass two values in the on_change method in odoo 8 ?

like below

<field name='test' on_change="get_func(test,'string')"/>
On 7/14/16, 5:29 AM

You can use the following method for implementing on_change method multiple fields with just one function.The fields must be in the same model.

in xml:

#in xml
<field name='test' on_change="get_func(test,'string')"/>
#and in python use
def get_func(self,value,field):
     ""here you can compare the field name and exec the desired lines using the if """

On 7/13/16, 8:08 AM

@api.onchange('staff_fname', 'staff_lname')

def funa(self):

if self.staff_fname and self.staff_lname:

s=(self.staff_fname or '') + (self.staff_lname or '')

self.staff_name = s.strip()

In this onchange function is execute when first anem and last anme are specified in your view.
Nikunj Antala
On 7/13/16, 7:56 AM

Hello Nikhil,

As per odoo 8 api you can directly set on-change method using @api.onchange no need to set into XML.


def onchange_name(self):
    self.name = 'what you want to save'

This function will execute when name field change.

Hope this helps.

can i pass 2 arguments in this methnod?

on 7/14/16, 5:20 AM

Why do you need to pass argument? because all fields of that model access directly in self... like. self.field name

Nikunj Antala
on 7/14/16, 6:06 AM

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 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: 7/13/16, 7:17 AM
Seen: 745 times
Last updated: 2/12/17, 10:15 PM