简体   繁体   中英

I want to compare date of duration of leaves with the current date in odoo python

Here is the program which i wrote and inherited from hr.holidays that if the selected date is before the current date then it should provide an error message. Code-

from datetime import date

if self.date_from <= date.today():
            print 'You cannot select the previous date'

But it gives the error-

TypeError: can't compare datetime.date to bool

Thanks

Hello Ujjwal Singh Baghel,

Try this below code,

#!/usr/bin/python
import datetime
i = datetime.datetime.now()

print ("Current date & time = %s" % i)


if self.date_from <= str(i):
            print 'You cannot select the previous date'

OR

from datetime import date
if self.date_from <= str(date.today()):
            print 'You cannot select the previous date'

For example

from datetime import date
if "10/07/2017" <= str(date.today()):
            print 'You cannot select the previous date'

Out put:

You cannot select the previous date

I hope my answer is helpful. If any query so comments, please.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM