gpt4 book ai didi

python - GNU Health - 时区错误

转载 作者:行者123 更新时间:2023-11-28 18:38:34 25 4
gpt4 key购买 nike

经过几天的搜索并尝试使用 pytz 和其他工具,我无法找到解决方案。

当用户在 GNU Health 中创建 Medication 打印输出列表时,会出现错误:

====== ERROR=======================                 
Traceback (most recent call last):
File "/trytond/protocols/jsonrpc.py", line 150, in _marshaled_dispatch
response['result'] = dispatch_method(method, params)
File "/trytond/protocols/jsonrpc.py", line 179, in _dispatch
res = dispatch(*args)
File "/trytond/protocols/dispatcher.py", line 161, in dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/trytond/report/report.py", line 144, in execute
type, data = cls.parse(action_report, records, data, {})
File "/trytond/modules/health/report/health_report.py", line 62, in parse
localcontext['print_date'] = get_print_date()
File "/trytond/modules/health/report/health_report.py", line 42, in get_print_date
return datetime.astimezone((dt.replace(tzinfo=None))
TypeError: astimezone() argument 1 must be datetime.tzinfo, not None
============END=================

我不知道如何解决这个问题

最佳答案

这是 the current code for get_print_date() :

def get_print_date():
Company = Pool().get('company.company')

timezone = None
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
if company.timezone:
timezone = pytz.timezone(company.timezone)

dt = datetime.now()
return datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone)

它似乎尝试(不正确,除非 TZ=UTC——您应该提交错误报告)执行以下操作:

import tzlocal # $ pip install tzlocal

def get_print_date():
Company = Pool().get('company.company')
company_id = Transaction().context.get('company')
company = company_id and Company(company_id)
timezone = company and company.timezone and pytz.timezone(company.timezone)
return datetime.now(timezone or tzlocal.get_localzone())

即,它返回公司时区或您本地时区的当前时间。

关于python - GNU Health - 时区错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29869220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com