I want to compare leaf duration date with current date in odoo python

Here is a program that I wrote and inherited from hr.holidays that if the selected date precedes the current date, it should contain an error message. The code -

from datetime import date

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

But he gives an error -

TypeError: can't compare datetime.date to bool

thank

+4
source share
1 answer

Hi Ujwal Singh Bagel,

Try this code below.

#!/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 instance

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

Conclusion:

You cannot select the previous date.

Hope my answer will be helpful. If any request comments like this, please.

+4
source

Source: https://habr.com/ru/post/1681009/


All Articles