Can now edit payment
This commit is contained in:
parent
d2c6f573f9
commit
f559c20b65
3 changed files with 62 additions and 26 deletions
|
@ -8,11 +8,13 @@
|
|||
{% for e in elements %}
|
||||
{% if refunds %}
|
||||
<a class="list-group-item" href="{% url 'refund_edit' pk=e.pk %}">
|
||||
{% elif payments %}
|
||||
<a class="list-group-item" href="{% url 'payment_edit' pk=e.pk %}">
|
||||
{% else %}
|
||||
<div class="list-group-item">
|
||||
{% endif %}
|
||||
{{ e.title }} le {{ e.date|date:"SHORT_DATE_FORMAT" }} : {{ e.eur_value }}€
|
||||
{% if refunds %}
|
||||
{% if refunds or payments %}
|
||||
</a>
|
||||
{% else %}
|
||||
</div>
|
||||
|
|
|
@ -7,4 +7,5 @@ urlpatterns = [
|
|||
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'^payments/(?P<pk>[0-9]+)/edit/$', views.payment_edit, name='payment_edit'),
|
||||
]
|
||||
|
|
|
@ -5,21 +5,9 @@ from refunding.forms import RefundFormPublic, PaymentForm
|
|||
from refunding.models import Payment, Refund
|
||||
|
||||
|
||||
@login_required
|
||||
def not_refunded_payments(request):
|
||||
payments = Payment.objects.filter(refund=None)
|
||||
value_sum = payments.aggregate(Sum('value')).get('value__sum')
|
||||
if value_sum:
|
||||
value_sum /= 100
|
||||
else:
|
||||
value_sum = 0
|
||||
|
||||
context = {
|
||||
'payments': payments,
|
||||
'sum': value_sum,
|
||||
'default_nothing': 'No payment to be refunded.'
|
||||
}
|
||||
return render(request, "refunding/payments.html", context)
|
||||
#############################
|
||||
# -------- Refunds -------- #
|
||||
#############################
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -53,6 +41,51 @@ def new_refund(request):
|
|||
return render(request, "refunding/refund_payment_detail.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required('refunding.change_refund')
|
||||
def refund_edit(request, pk):
|
||||
refund = get_object_or_404(Refund, pk=pk)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = RefundFormPublic(request.POST, instance=refund)
|
||||
if form.is_valid():
|
||||
refund = form.save()
|
||||
refund.user = request.user
|
||||
refund.save()
|
||||
return redirect('latest_refunds')
|
||||
else:
|
||||
form = RefundFormPublic(instance=refund)
|
||||
|
||||
context = {
|
||||
'form': form,
|
||||
'title': 'Edit refund'
|
||||
}
|
||||
|
||||
return render(request, 'refunding/refund_payment_detail.html', context)
|
||||
|
||||
|
||||
##############################
|
||||
# -------- Payments -------- #
|
||||
##############################
|
||||
|
||||
|
||||
@login_required
|
||||
def not_refunded_payments(request):
|
||||
payments = Payment.objects.filter(refund=None)
|
||||
value_sum = payments.aggregate(Sum('value')).get('value__sum')
|
||||
if value_sum:
|
||||
value_sum /= 100
|
||||
else:
|
||||
value_sum = 0
|
||||
|
||||
context = {
|
||||
'payments': payments,
|
||||
'sum': value_sum,
|
||||
'default_nothing': 'No payment to be refunded.'
|
||||
}
|
||||
return render(request, "refunding/payments.html", context)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required('refunding.add_payment')
|
||||
def new_payment(request):
|
||||
|
@ -75,23 +108,23 @@ def new_payment(request):
|
|||
|
||||
|
||||
@login_required
|
||||
@permission_required('refunding.change_refund')
|
||||
def refund_edit(request, pk):
|
||||
refund = get_object_or_404(Refund, pk=pk)
|
||||
@permission_required('refunding.change_payment')
|
||||
def payment_edit(request, pk):
|
||||
payment = get_object_or_404(Payment, pk=pk)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = RefundFormPublic(request.POST, instance=refund)
|
||||
form = PaymentForm(request.POST, instance=payment)
|
||||
if form.is_valid():
|
||||
refund = form.save()
|
||||
refund.user = request.user
|
||||
refund.save()
|
||||
return redirect('latest_refunds')
|
||||
payment = form.save(commit=False)
|
||||
payment.user = request.user
|
||||
payment.save()
|
||||
return redirect('not_refunded_payments')
|
||||
else:
|
||||
form = RefundFormPublic(instance=refund)
|
||||
form = PaymentForm(instance=payment)
|
||||
|
||||
context = {
|
||||
'form': form,
|
||||
'title': 'Edit refund'
|
||||
'title': 'Edit payment'
|
||||
}
|
||||
|
||||
return render(request, 'refunding/refund_payment_detail.html', context)
|
||||
|
|
Loading…
Reference in a new issue