Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
8297 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 23
2261
"Wrong value for %s: %r" % (self, value) แก้ไขแล้ว
2
ต.ค. 23
2478
3
ต.ค. 23
9404
1
ก.ย. 23
3603
2
ส.ค. 23
4576