"datetime.date" 类型的对象在 python 中没有 len ()"
Object of type "datetime.date" has no len ()" in python
我在 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
当我 运行 这个函数时,它会出现这样的错误
"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())])
我只想得到今天有截止日期的项目
有什么建议吗?
谢谢
您应该将日期转换为字符串以进行比较:
project = self.env['project.project'].search([('deadline', '=', str(now.date()))])
我在 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
当我 运行 这个函数时,它会出现这样的错误
"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())])
我只想得到今天有截止日期的项目
有什么建议吗?
谢谢
您应该将日期转换为字符串以进行比较:
project = self.env['project.project'].search([('deadline', '=', str(now.date()))])