コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
14647 ビュー

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
5322
1
3月 15
4367
0
4月 24
1857
4
11月 23
5950
1
10月 23
2024