From 8367f807a3251d8c888fb4cdd788f8b5c768d176 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 4 Jun 2016 13:17:18 +0200 Subject: [PATCH] Add ability to delete refunds and payments --- .../refunding/refund_payment_detail.html | 15 ++++++++- refunding/urls.py | 6 ++-- refunding/views.py | 31 +++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/refunding/templates/refunding/refund_payment_detail.html b/refunding/templates/refunding/refund_payment_detail.html index 5b1afad..844ffe5 100644 --- a/refunding/templates/refunding/refund_payment_detail.html +++ b/refunding/templates/refunding/refund_payment_detail.html @@ -17,7 +17,20 @@ {% endblock %} {% block content %} -

{% block title %}{{ title }}{% endblock %}

+

+ {% block title %}{{ title }}{% endblock %} +
+ {% if payment and perms.refunding.delete_payment %} + + + + {% elif refund and perms.refunding.delete_refund %} + + + + {% endif %} +
+

{% csrf_token %} {{ form.media }} diff --git a/refunding/urls.py b/refunding/urls.py index 7560c72..7210472 100644 --- a/refunding/urls.py +++ b/refunding/urls.py @@ -2,10 +2,12 @@ from django.conf.urls import url from refunding import views urlpatterns = [ - url(r'^payments/$', views.not_refunded_payments, name='not_refunded_payments'), url(r'^refunds/$', views.latest_refunds, name='latest_refunds'), url(r'^refunds/new/$', views.new_refund, name='new_refund'), - url(r'^payments/new/$', views.new_payment, name='new_payment'), 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'^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'), + url(r'^payments/(?P[0-9]+)/delete/$', views.payment_delete, name='payment_delete'), ] diff --git a/refunding/views.py b/refunding/views.py index 9da287c..d55d976 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -1,3 +1,4 @@ +from django.contrib import messages from django.contrib.auth.decorators import login_required, permission_required from django.db.models import Sum from django.shortcuts import render, redirect, get_object_or_404 @@ -58,12 +59,25 @@ def refund_edit(request, pk): context = { 'form': form, - 'title': 'Edit refund' + 'title': 'Edit refund', + 'refund': refund } return render(request, 'refunding/refund_payment_detail.html', context) +@login_required +@permission_required('refunding.delete_refund') +def refund_delete(request, pk): + refund = get_object_or_404(Refund, pk=pk) + + refund.delete() + + messages.success(request, "Refund deleted successfully") + + return latest_refunds(request) + + ############################## # -------- Payments -------- # ############################## @@ -124,7 +138,20 @@ def payment_edit(request, pk): context = { 'form': form, - 'title': 'Edit payment' + 'title': 'Edit payment', + 'payment': payment } return render(request, 'refunding/refund_payment_detail.html', context) + + +@login_required +@permission_required('refunding.delete_payment') +def payment_delete(request, pk): + payment = get_object_or_404(Payment, pk=pk) + + payment.delete() + + messages.success(request, "Payment deleted successfully") + + return not_refunded_payments(request)