[英]can't compare datetime.date to bool
when i save the atttachment i get this error " can't compare datetime.date to bool " how can i solve thit issue this is the code当我保存附件时,我收到此错误“无法将 datetime.date 与 bool 进行比较”我该如何解决这个问题,这是代码
from datetime import datetime, date, timedelta
from odoo import models, fields, api, _
from odoo.exceptions import Warning
class HrEmployeeDocument(models.Model):
_name = 'hr.employee.document'
_description = 'HR Employee Documents'
@api.constrains('expiry_date')
def check_expr_date(self):
for each in self:
exp_date = each.expiry_date
if expiry_date < date.today():
raise Warning('Your Document Is Already Expired.')
expiry_date = fields.Date(string='Expiry Date', copy=False)
The issue is this line问题是这条线
expiry_date = fields.Date(string='Expiry Date', copy=False)
In the documentation of the odoo
-> field
, it requires a date string, what you provided string='Expiry Date'
, which is meanless, thus the expiry_date
will be assigned a bool which is False
, since it is not a valid data string.在
odoo
-> field
的文档中,它需要一个日期字符串,你提供的string='Expiry Date'
,这是没有意义的,因此expiry_date
将被分配一个 bool 是False
,因为它不是一个有效的数据字符串.
You need to change to:您需要更改为:
expiry_date = fields.Date(string='2014-06-15', copy=False)
And it should work.它应该工作。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.