Thai Laoquoc
Thai Laoquoc

Reputation: 115

Object of type "datetime.date" has no len ()" in python

I have this code like this in odoo 11

@api.multi
def report_team(self):
    teambao = self.env['hr.department'].search([])
    tongteam = len(teambao)
    i = 0
    while i < tongteam:
        if teambao[i].id:
            now = datetime.now()
            print(now.date())

            project = self.env['project.project'].search([('deadline', '=', now.date())])
            print (project)
        i = i + 1

And when i run this function, it getting error like this

"object of type 'datetime.date' has no len()" while evaluating 'model.report_team()' 
in report_team
project = self.env['project.project'].search([('deadline', '=', now.date())])

All I want is get the project that have deadline at today

Any suggest for me?

Thanks

Upvotes: 5

Views: 13578

Answers (1)

blhsing
blhsing

Reputation: 106445

You should convert the date to a string for comparison:

project = self.env['project.project'].search([('deadline', '=', str(now.date()))])

Upvotes: 6

Related Questions