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

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...'))

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ม.ค. 20
5108
3
มี.ค. 22
26413
2
ก.ค. 24
2652
1
มิ.ย. 24
5128
1
ต.ค. 23
10830