5

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

blhsing
  • 91,368
  • 6
  • 71
  • 106
Thai Laoquoc
  • 115
  • 2
  • 2
  • 10

1 Answers1

6

You should convert the date to a string for comparison:

project = self.env['project.project'].search([('deadline', '=', str(now.date()))])
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • hi, i need help with problem that field "deadline" is a datetime field, how can make a comparison with str data like your answer. Anyway, your answer will right in some sittuation. – Thai Laoquoc Oct 17 '18 at 04:51