Odoo Help

Welcome!

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

0

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

By
kalyan
on 4/28/14, 8:20 AM 1,233 views

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

2

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 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
0

Nehal

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

Hi,

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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