我有一个 Odoo 服务器,其中实例具有以下条件并且
date.today()
昨天返回。以下条件返回 true:
if invoice.invoice_date > date.today():
errors.append("- Please, make sure the invoice date is set to either the same as or before Today.")
但是,在同一台电脑中使用 python shell 会返回正确的日期。请注意,时间是 2 月 24 日凌晨 1:20,并且两个 python 都在同一环境中。
所以,你能告诉我 python
date.today()
是否会受到任何 context
的影响吗?
Odoo 日期存储为 UTC。 正如日期时间文档中所指定的,今天返回本地当前日期,这可能是问题的原因。 你应该阅读关于天真的和有意识的约会。 https://docs.python.org/3/library/datetime.html#aware-and-naive-objects 希望有帮助