This question has been flagged
1 Reply
2351 Views

I have created a custom module which stores a bunch of dates which cant be selected in the sales module for order date

Is there away to prevent the selection of these dates?

My initial thought was raise error when a date is selected (onchange method) however once an incorrect date has been selected, the error consistently popups up without enough time to change the date.

Avatar
Discard
Best Answer

If you need to do it when user selects the date, you would need to make the change in the JS.

The simple way to do it using constraint. 

@api.constrains('order_date')
def add_validation(self):
if self.order_date == self.my_date:
raise ValidationError('This date is not allowed! Please select different date.')


Avatar
Discard
Author

At what point would this through the error? on selection or on save

Author

Any hints on the way you would do it with javascript?

Sorry, no idea about that for now.