2017-08-31 31 views
1

我正在嘗試編寫一個返回消息並同時更新值的onchange。到目前爲止,它顯示消息,但該字段保持不變。我的代碼是:在onchange方法中顯示消息並將值賦給字段

@api.onchange('changed_field') 
def my_onchange_method(self):  
    if self.other_field: 
     self.changed_field=False 
     raise Warning('Some message.') 

我覺得我的錯誤是在發送消息的方式,任何人都可以告訴我如何在odoo 9實現這一目標?謝謝。

回答

2

我認爲你正在提高內置警告異常,這可能是爲什麼字段沒有更新(我認爲當引發異常時回滾更改)。

試試這個:

@api.onchange('changed_field') 
def my_onchange_method(self):  
    if self.other_field: 
     self.changed_field = False 
     return { 
      'warning': { 
       'title': 'TITLE OF THE WARNING MESSAGE BOX', 
       'message': 'YOUR WARNING MESSAGE', 
      } 
     } 

我可以證實這個工程至少odoo 8.這將可能是odoo 9

+0

它的工作很好地工作。謝謝 ;) – Dayana

0
def onchange_amount_paid(self, cr, uid, ids, amount_paid, context=None): 


res = {'value':{}} 

if amount_paid: 

if fee_type==1 and amount_paid<70: 

warning = { 'title': ("Warning"), 'message': ('registration account minimum payment is 70'), } 

return {'value': res.get('value',{}), 'warning':warning} 

return {'value': res.get('value',{})}