2015-04-25 38 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

您是否設置了機構/公司時區?

您可以檢查/設置你的公司時區黨 - >配置 - >公司 - >時區