Reputation: 1538
I am trying to write an onchange that returns a message and updates a value at the same time. So far it displays the message but the field remains the same. The code I have is:
@api.onchange('changed_field')
def my_onchange_method(self):
if self.other_field:
self.changed_field=False
raise Warning('Some message.')
I think my mistake is in the way of sending the message, could anyone tell me how to achieve this in odoo 9? Thanks.
Upvotes: 1
Views: 1036
Reputation: 32
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',{})}
Upvotes: 0
Reputation: 1080
I think you're raising the builtin Warning exception, which is probably why the field isn't updated (I think the changes are rolled back when the exception is raised).
Try this instead :
@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',
}
}
I can confirm this works at least for odoo 8. It will probably work for odoo 9.
Upvotes: 4