Fix bug when no payment to refund

This commit is contained in:
Gabriel Augendre 2016-06-04 03:49:37 +02:00
parent 31a077ef83
commit b3674b516d
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1

View file

@ -1,17 +1,22 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db.models import Sum from django.db.models import Sum
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from refunding.forms import RefundForm, RefundFormPublic from refunding.forms import RefundFormPublic
from refunding.models import Payment, Refund from refunding.models import Payment, Refund
@login_required @login_required
def not_refunded_payments(request): def not_refunded_payments(request):
payments = Payment.objects.filter(refund=None) payments = Payment.objects.filter(refund=None)
sum = payments.aggregate(Sum('value')).get('value__sum') / 100 value_sum = payments.aggregate(Sum('value')).get('value__sum')
if value_sum:
value_sum /= 100
else:
value_sum = 0
context = { context = {
'payments': payments, 'payments': payments,
'sum': sum, 'sum': value_sum,
'default_nothing': 'No payment to be refunded.' 'default_nothing': 'No payment to be refunded.'
} }
return render(request, "refunding/payments.html", context) return render(request, "refunding/payments.html", context)