From b3674b516d1d283bbee6966b337149aaed1397c6 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 4 Jun 2016 03:49:37 +0200 Subject: [PATCH] Fix bug when no payment to refund --- refunding/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/refunding/views.py b/refunding/views.py index f13c56e..4dbafa4 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -1,17 +1,22 @@ from django.contrib.auth.decorators import login_required from django.db.models import Sum from django.shortcuts import render, redirect -from refunding.forms import RefundForm, RefundFormPublic +from refunding.forms import RefundFormPublic from refunding.models import Payment, Refund @login_required def not_refunded_payments(request): 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 = { 'payments': payments, - 'sum': sum, + 'sum': value_sum, 'default_nothing': 'No payment to be refunded.' } return render(request, "refunding/payments.html", context)