跳至內容
選單
此問題已被標幟
1 回覆
8078 瀏覽次數

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
2012
2
10月 23
2209
3
10月 23
8805
1
9月 23
3325
2
8月 23
4233