Add the ability to edit a refund

This commit is contained in:
Gabriel Augendre 2016-06-04 04:29:21 +02:00
parent b3674b516d
commit d0950732aa
No known key found for this signature in database
GPG key ID: D2B6A5B41FC438B1
4 changed files with 37 additions and 8 deletions

View file

@ -17,8 +17,8 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h1>{% block title %}New refund{% endblock %}</h1> <h1>{% block title %}{{ title }}{% endblock %}</h1>
<form action="{% url 'new_refund' %}" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.media }} {{ form.media }}
{{ form|crispy }} {{ form|crispy }}

View file

@ -6,9 +6,17 @@
{% endif %} {% endif %}
<div class="list-group"> <div class="list-group">
{% for e in elements %} {% for e in elements %}
<div class="list-group-item"> {% if refunds %}
{{ e.title }} le {{ e.date|date:"SHORT_DATE_FORMAT" }} : {{ e.eur_value }}€ <a class="list-group-item" href="{% url 'refund_edit' pk=e.pk %}">
</div> {% else %}
<div class="list-group-item">
{% endif %}
{{ e.title }} le {{ e.date|date:"SHORT_DATE_FORMAT" }} : {{ e.eur_value }}€
{% if refunds %}
</a>
{% else %}
</div>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}

View file

@ -5,4 +5,5 @@ urlpatterns = [
url(r'^payments/$', views.not_refunded_payments, name='not_refunded_payments'), url(r'^payments/$', views.not_refunded_payments, name='not_refunded_payments'),
url(r'^refunds/$', views.latest_refunds, name='latest_refunds'), url(r'^refunds/$', views.latest_refunds, name='latest_refunds'),
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'),
] ]

View file

@ -1,6 +1,6 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db.models import Sum from django.db.models import Sum
from django.shortcuts import render, redirect from django.shortcuts import render, redirect, get_object_or_404
from refunding.forms import RefundFormPublic from refunding.forms import RefundFormPublic
from refunding.models import Payment, Refund from refunding.models import Payment, Refund
@ -45,6 +45,26 @@ def new_refund(request):
form = RefundFormPublic() form = RefundFormPublic()
context = { context = {
'form': form 'form': form,
'title': 'New refund'
} }
return render(request, "refunding/new_refund.html", context) return render(request, "refunding/edit_new_refund.html", context)
@login_required
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/edit_new_refund.html', context)