2015-04-25 18 views
3

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

当用户创建在GNU卫生给出错误的药物打印出清单:

====== 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================= 

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

+1

是什么'datetime.astimezone((dt.replace(tzinfo =无))'应该做的 –

+0

? @PadraicCunningham:我会理解它是否会引发:'ValueError:astimezone()不能应用于天真的日期时间,那么它将等于 'dt.replace(tzinfo = None).astimezone()', TypeError'建议'datetime.now(timezone.utc).astimezone(tz = None)'类似代码(在Python 3.3+之前 其中空参数被设置为本地时区: ['.astimezone(tz)':* Changed在版本3.3中:tz现在可以省略*](https://docs.python.org/3/library/datetime.html#datetime.dateti me.astimezone)。无论如何,使用'klass.method(obj,* args)' 而不是'obj.method(* args)'是一种不好的风格。 – jfs

回答

1

这里的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()) 

即它返回当前时间在company的时区或在本地时区。

+0

这很有道理,我无法追踪回溯中发生的一切。 –

0

您是否设置了机构/公司时区?

您可以检查/设置你的公司时区党 - >配置 - >公司 - >时区