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

Hello, Odoo community,

What is the best way in Odoo 11 Saas to add date validation? if I have an end_date field and start_date field, I would like to ensure that end_date is greater than start_end. How can I do that?

if it helps

view_type=form

model=account.invoice

الصورة الرمزية
إهمال
أفضل إجابة

Dear Shaheryar,

Try This:

from odoo.exceptions import  ValidationError

    @api.multi
    @api.constrains('end_date', 'start_date')
    def date_constrains(self):

              for rec in self:

                      if rec.end_date < rec.start_date:

                           raise ValidationError(_('Sorry, End Date Must be greater Than Start Date...'))


I hope I help you...

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Hello Ayman,

Thanks for replying. How can I do this on Odoo Studio, the online Saas version?

I tried to use the following in Automated actions but that did not work.

def date_constrains(self):

              for rec in self:

                      if rec.end_date < rec.start_date:

                           raise ValidationError(_('Sorry, End Date Must be greater Than Start Date...'))

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
4
يناير 20
5049
3
مارس 22
26352
2
يوليو 24
2605
1
يونيو 24
5069
1
أكتوبر 23
10748