Unfortunately I cant comment on @Axel answer.
According
documentation _constraints is deprecated and I shall use constraints
decorator, so the right way in odoo 9.x would be something like this?
def _check_comp_min(self):
if 0 < self.comp_min < self.comp_max:
return True
self.comp_min = None # this is not ideal, as value before modification should be here.
return False
@api.onchange('comp_max', 'comp_min'):
def validation_comp_min(self):
if not self._check_comp_min():
return {
'warning': {
'title': 'Error',
'message': 'You have entered wrong value for component'
}
}
return True
@api.constrains('comp_max', 'comp_min'):
def validation_comp_max(self):
validation_result = self._check_comp_min()
if validation_result != True:
raise ValidationError('You have entered wrong value for component')
This way I would have just one validation function, but it have to be called twice for onchange (to validate immediatelly) and also on constraint so it is validated when saving. Or is there something similar like Django models have? Seems too much code for simple validation to be executed on change and constraint as well...