تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
8109 أدوات العرض

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
أكتوبر 23
2020
2
أكتوبر 23
2245
3
أكتوبر 23
8847
1
سبتمبر 23
3337
2
أغسطس 23
4255