Odoo Help


how to validate star_date is less than the current date or not

on 4/28/14, 8:20 AM 2,021 views

i have selected the start date. this selected date how will i validate/check to current date?


Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/28/14, 8:29 AM

Hi, you can use the below code to validate...

from datetime import datetime

start = datetime(2015, 1, 1)
current = datetime.now()
print current
print start < current

You can use current date as default

'today_date' : fields.date.context_today



| 5 2 8
Ahmadabad, India
On 4/28/14, 8:49 AM


You can do something like below:

def _check_dates(self, cr, uid, ids, context=None):
    if context == None:
        context = {}
    obj_task = self.browse(cr, uid, ids[0], context=context)
    start = obj_task.start_date or False
    end = time.strftime('%Y-%m-%d')
    if start and end :
        if start < end:
            return False
    return True

_constraints = [
    (_check_dates, 'Error ! Start Date must be greater then Current Date', ['start_date'])

You can also apply this method on onchange method of start_date.

Hope this may help you.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/28/14, 8:20 AM
Seen: 2021 times
Last updated: 3/16/15, 8:10 AM