Skip to Content
Menu
This question has been flagged
2 Replies
9877 Views

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
4
Jan 20
4362
3
Mar 22
24845
2
Jul 24
941
1
Jun 24
3563
1
Oct 23
8590