콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
14681 화면

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

like below

<field name='test' on_change="get_func(test,'string')"/>
아바타
취소
베스트 답변

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.

아바타
취소
작성자

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

베스트 답변

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

아바타
취소
베스트 답변

@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.
아바타
취소
작성자

Thanks

관련 게시물 답글 화면 활동
1
3월 15
5366
1
3월 15
4414
0
4월 24
1928
4
11월 23
6030
1
10월 23
2066