跳至内容
菜单
此问题已终结
1 回复
7472 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
编写者

Thank you very much Niyas.

相关帖文 回复 查看 活动
1
10月 23
1013
2
10月 23
1331
3
10月 23
7197
1
9月 23
2504
2
8月 23
3022