Skip to Content
Menu
This question has been flagged
1 Reply
7027 Views

Hello everyone,

On Odoo v12, If I enter:

@api.onchange('date')if self.date > date.today():
    raise ValidationError(('Error: Check your date!' ))

The code runs fine and date values are checked for the condition.

If I enter:

@api.onchange('date')if self.date > date.today() or self.date == False:
    raise ValidationError(('Error: Check your date!' ))

I've got the error:

TypeError: '>' not supported between instances of 'bool' and 'datetime.date'

Also tried with if self.date > date.today() or self.date == "" with no luck.

Can anyone help me please?

Thank you in advance

Avatar
Discard
Best Answer

Hi,

Update the code like this,


@api.onchange('date')
def change_date(self):
if self.date and self.date > date.today():
raise ValidationError(_('Error: Check your date!'))


Thanks

Avatar
Discard
Author

Thank you very much Niyas.

Related Posts Replies Views Activity
1
Oct 23
363
2
Oct 23
672
3
Oct 23
5977
1
Sep 23
1968
2
Aug 23
1963