Fix timezones in PDF reports

This commit is contained in:
Raphael Michel
2016-12-05 13:37:12 +01:00
parent 34b937273a
commit 5ca82a922a

View File

@@ -2,6 +2,7 @@ import tempfile
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
from decimal import Decimal from decimal import Decimal
import pytz
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles import finders from django.contrib.staticfiles import finders
@@ -38,7 +39,8 @@ class Report(BaseExporter):
return 'report-%s.pdf' % self.event.slug, 'application/pdf', self.create() return 'report-%s.pdf' % self.event.slug, 'application/pdf', self.create()
def get_filename(self): def get_filename(self):
return "%s-%s.pdf" % (self.name, now().strftime("%Y-%m-%d-%H-%M-%S")) tz = pytz.timezone(self.event.settings.timezone)
return "%s-%s.pdf" % (self.name, now().astimezone(tz).strftime("%Y-%m-%d-%H-%M-%S"))
@staticmethod @staticmethod
def register_fonts(): def register_fonts():
@@ -274,6 +276,7 @@ class OrderTaxListReport(Report):
headlinestyle = self.get_style() headlinestyle = self.get_style()
headlinestyle.fontSize = 15 headlinestyle.fontSize = 15
headlinestyle.fontName = 'OpenSansBd' headlinestyle.fontName = 'OpenSansBd'
tz = pytz.timezone(self.event.settings.timezone)
tax_rates = set( tax_rates = set(
self.event.orders.exclude(payment_fee=0).values_list('payment_fee_tax_rate', flat=True) self.event.orders.exclude(payment_fee=0).values_list('payment_fee_tax_rate', flat=True)
@@ -340,7 +343,7 @@ class OrderTaxListReport(Report):
tdata.append( tdata.append(
[ [
op['order__code'], op['order__code'],
date_format(op['order__datetime'], "SHORT_DATE_FORMAT"), date_format(op['order__datetime'].astimezone(tz), "SHORT_DATE_FORMAT"),
status_labels[op['order__status']], status_labels[op['order__status']],
date_format(op['order__payment_date'], "SHORT_DATE_FORMAT") if op['order__payment_date'] else '', date_format(op['order__payment_date'], "SHORT_DATE_FORMAT") if op['order__payment_date'] else '',
str(op['order__total']) str(op['order__total'])