From 6cffd58a8dad1671cd118eb12c0e152deac9751f Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 17 Aug 2016 17:36:19 +0200 Subject: [PATCH] Add view for already refunded payments --- refunding/templates/refunding/payments.html | 1 + .../templates/refunding/refunded_payments.html | 10 ++++++++++ refunding/urls.py | 1 + refunding/views.py | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 refunding/templates/refunding/refunded_payments.html diff --git a/refunding/templates/refunding/payments.html b/refunding/templates/refunding/payments.html index 91be5d6..08c99a5 100644 --- a/refunding/templates/refunding/payments.html +++ b/refunding/templates/refunding/payments.html @@ -13,4 +13,5 @@ {% endif %} {% include 'refunding/elements_list.html' with elements=payments %} + Only refunded payments {% endblock %} \ No newline at end of file diff --git a/refunding/templates/refunding/refunded_payments.html b/refunding/templates/refunding/refunded_payments.html new file mode 100644 index 0000000..ea62ad3 --- /dev/null +++ b/refunding/templates/refunding/refunded_payments.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% load l10n %} + +{% block content %} +

+ {% block title %}Refunded payments{% endblock %} +

+ {% include 'refunding/elements_list.html' with elements=refunded %} + Only not refunded payments +{% endblock %} \ No newline at end of file diff --git a/refunding/urls.py b/refunding/urls.py index 7210472..744fc9f 100644 --- a/refunding/urls.py +++ b/refunding/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ url(r'^refunds/new/$', views.new_refund, name='new_refund'), url(r'^refunds/(?P[0-9]+)/edit/$', views.refund_edit, name='refund_edit'), url(r'^refunds/(?P[0-9]+)/delete/$', views.refund_delete, name='refund_delete'), + url(r'^refunded-payments/$', views.already_refunded_payments, name='already_refunded_payments'), url(r'^payments/$', views.not_refunded_payments, name='not_refunded_payments'), url(r'^payments/new/$', views.new_payment, name='new_payment'), url(r'^payments/(?P[0-9]+)/edit/$', views.payment_edit, name='payment_edit'), diff --git a/refunding/views.py b/refunding/views.py index 771bfd2..c6c98c0 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -163,3 +163,20 @@ def payment_delete(request, pk): messages.success(request, "Payment deleted successfully") return not_refunded_payments(request) + + +@login_required +def already_refunded_payments(request): + refunded = Payment.objects.exclude(refund=None).order_by('-date', '-id') + value_sum = refunded.aggregate(Sum('value')).get('value__sum') + if value_sum: + value_sum /= 100 + else: + value_sum = 0 + + context = { + 'refunded': refunded, + 'sum': value_sum, + 'default_nothing': 'No refunded payment :)' + } + return render(request, "refunding/refunded_payments.html", context)