GNU Health - Time Zone Errors

After days of searching and trying to use pytz and other tools, I can't seem to find a solution.

When a user creates a list of drug printouts in GNU Health, an error message is thrown:

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

      

I'm not sure how to fix this problem.

+3


source to share


2 answers


Here's the current code forget_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)

      

It seems to be trying (incorrect if TZ=UTC

- you should file a bug report) to do the following:



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())

      

ie, it either returns the current time in your timezone company

or your local timezone.

+1


source


Have you set the time zone for your institution / company?



You can check / set your company timezone in Party → Configuration → Companies → Timezone

0


source







All Articles