Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
2906 Представления

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.

  1. Validation success case is working fine.

  2. 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

Лучший ответ

Hello,

You can add constraints also for this.

Аватар
Отменить
Лучший ответ

Hi,

Update the below lines of your code and see,


if order > 0:
         return raise ValidationError(_('Warning message'))
else:
         reparaciones = super(Reparaciones, self).create(vals)
         return reparaciones


Thanks

Аватар
Отменить