I am trying to validate a "capacity" field with onchange decorator but for some reason when I send the warning message the previous line stops working. The template updates the field fine whitout the warning
@api.onchange('capacity')
def check_capacity_values(self):
if self.capacity<0:
self.capacity=0
raise Warning(_('wrong capacity.'))
You can use a dictionary as return value for methods decorated by api.onchange
. The key for warning messages will be warning
and the value another dictionary with keys title
and message
. An example:
return {
'warning': {'title': "WARNING!",
'message': "It isn't allowed to have a negative capacity!"}
}