Greetings.
I'm overriding the repair.order form, I added a custom validation where if it passes the record is created. But if the validation fails I raise a warning showing the validation error.
Validation success case is working fine.
After the warning is closed the window gets stuck (menu is not working, buttons not working as well except the create one, which shows the warning message again)
How can i correctly prevent the create method if a condition is not meet ?
This is what I've done:
@api.model
def create(self, vals):
OrderRepair = self.env['repair.order']
order = OrderRepair.search_count([ ('vehicle_id', '=', int(vals['vehicle_id'])), '|', ('state', '=', 'under_repair'), ('state', '=', 'confirmed')])
if order > 0:
raise UserError(_('Warning message'))
return self
else:
reparaciones = super(Reparaciones, self).create(vals)
return reparaciones
Thanks
Hello, thank you both for your answers.
@Mital Vaghani I changed my approach to use constraints but the applications gets stuck as well, I can't return to a previous section (only refreshing the page works) after the validation button is clicked , it only prompts me again the validation error.
@Niyas Raphy When i return the "raise ValidationError" the application stops working and starts showing errors that aren't related to the issue