Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
14637 Weergaven

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

like below

<field name='test' on_change="get_func(test,'string')"/>
Avatar
Annuleer
Beste antwoord

Hello Nikhil,

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


Example:

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

This function will execute when name field change.


Hope this helps.

Avatar
Annuleer
Auteur

can i pass 2 arguments in this methnod?

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

Beste antwoord

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
@api.multi
def get_func(self,value,field):
     ""here you can compare the field name and exec the desired lines using the if """

Avatar
Annuleer
Beste antwoord

@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.
Avatar
Annuleer
Auteur

Thanks

Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 15
5316
1
mrt. 15
4360
0
apr. 24
1853
4
nov. 23
5946
1
okt. 23
2022