Add view for already refunded payments

This commit is contained in:
Gabriel Augendre 2016-08-17 17:36:19 +02:00
parent fba021da10
commit 6cffd58a8d
4 changed files with 29 additions and 0 deletions

View file

@ -13,4 +13,5 @@
{% endif %} {% endif %}
</h1> </h1>
{% include 'refunding/elements_list.html' with elements=payments %} {% include 'refunding/elements_list.html' with elements=payments %}
<a href="{% url 'already_refunded_payments' %}">Only refunded payments</a>
{% endblock %} {% endblock %}

View file

@ -0,0 +1,10 @@
{% extends 'base.html' %}
{% load l10n %}
{% block content %}
<h1>
{% block title %}Refunded payments{% endblock %}
</h1>
{% include 'refunding/elements_list.html' with elements=refunded %}
<a href="{% url 'not_refunded_payments' %}">Only not refunded payments</a>
{% endblock %}

View file

@ -6,6 +6,7 @@ urlpatterns = [
url(r'^refunds/new/$', views.new_refund, name='new_refund'), url(r'^refunds/new/$', views.new_refund, name='new_refund'),
url(r'^refunds/(?P<pk>[0-9]+)/edit/$', views.refund_edit, name='refund_edit'), url(r'^refunds/(?P<pk>[0-9]+)/edit/$', views.refund_edit, name='refund_edit'),
url(r'^refunds/(?P<pk>[0-9]+)/delete/$', views.refund_delete, name='refund_delete'), url(r'^refunds/(?P<pk>[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/$', views.not_refunded_payments, name='not_refunded_payments'),
url(r'^payments/new/$', views.new_payment, name='new_payment'), url(r'^payments/new/$', views.new_payment, name='new_payment'),
url(r'^payments/(?P<pk>[0-9]+)/edit/$', views.payment_edit, name='payment_edit'), url(r'^payments/(?P<pk>[0-9]+)/edit/$', views.payment_edit, name='payment_edit'),

View file

@ -163,3 +163,20 @@ def payment_delete(request, pk):
messages.success(request, "Payment deleted successfully") messages.success(request, "Payment deleted successfully")
return not_refunded_payments(request) 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)