Add ability to delete refunds and payments
This commit is contained in:
parent
eab171a5c3
commit
8367f807a3
3 changed files with 47 additions and 5 deletions
|
@ -17,7 +17,20 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% block title %}{{ title }}{% endblock %}</h1>
|
||||
<h1>
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
<div class="btn-group pull-right">
|
||||
{% if payment and perms.refunding.delete_payment %}
|
||||
<a class="btn btn-danger" href="{% url 'payment_delete' payment.pk %}">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</a>
|
||||
{% elif refund and perms.refunding.delete_refund %}
|
||||
<a class="btn btn-danger" href="{% url 'refund_delete' refund.pk %}">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</h1>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.media }}
|
||||
|
|
|
@ -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<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'^payments/$', views.not_refunded_payments, name='not_refunded_payments'),
|
||||
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]+)/delete/$', views.payment_delete, name='payment_delete'),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue