diff --git a/refunding/forms.py b/refunding/forms.py index d46f732..9c1df8d 100644 --- a/refunding/forms.py +++ b/refunding/forms.py @@ -45,3 +45,16 @@ class RefundFormPublic(RefundForm): } ) ) + + +class PaymentForm(forms.ModelForm): + class Meta: + model = Payment + fields = ('title', 'value', 'date') + widgets = { + 'date': DateTimePicker( + options={ + "format": "YYYY-MM-DD" + } + ), + } diff --git a/refunding/templates/refunding/payments.html b/refunding/templates/refunding/payments.html index 1725d42..fd9b786 100644 --- a/refunding/templates/refunding/payments.html +++ b/refunding/templates/refunding/payments.html @@ -2,6 +2,15 @@ {% load l10n %} {% block content %} -

{% block title %}Payments to refund{% endblock %}

+

+ {% block title %}Payments to refund{% endblock %} + {% if user.is_authenticated %} +
+ + + +
+ {% endif %} +

{% include 'refunding/elements_list.html' with elements=payments %} {% endblock %} \ No newline at end of file diff --git a/refunding/templates/refunding/edit_new_refund.html b/refunding/templates/refunding/refund_payment_detail.html similarity index 100% rename from refunding/templates/refunding/edit_new_refund.html rename to refunding/templates/refunding/refund_payment_detail.html diff --git a/refunding/urls.py b/refunding/urls.py index c3e66dc..31cd50d 100644 --- a/refunding/urls.py +++ b/refunding/urls.py @@ -5,5 +5,6 @@ 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'), ] diff --git a/refunding/views.py b/refunding/views.py index 190b9e7..69580e8 100644 --- a/refunding/views.py +++ b/refunding/views.py @@ -1,7 +1,7 @@ from django.contrib.auth.decorators import login_required from django.db.models import Sum from django.shortcuts import render, redirect, get_object_or_404 -from refunding.forms import RefundFormPublic +from refunding.forms import RefundFormPublic, PaymentForm from refunding.models import Payment, Refund @@ -48,7 +48,27 @@ def new_refund(request): 'form': form, 'title': 'New refund' } - return render(request, "refunding/edit_new_refund.html", context) + return render(request, "refunding/refund_payment_detail.html", context) + + + +@login_required +def new_payment(request): + if request.method == 'POST': + form = PaymentForm(request.POST) + if form.is_valid(): + payment = form.save(commit=False) + payment.user = request.user + payment.save() + return redirect('not_refunded_payments') + else: + form = PaymentForm() + + context = { + 'form': form, + 'title': 'New payment' + } + return render(request, "refunding/refund_payment_detail.html", context) @login_required @@ -67,4 +87,4 @@ def refund_edit(request, pk): 'form': form, 'title': 'Edit refund' } - return render(request, 'refunding/edit_new_refund.html', context) + return render(request, 'refunding/refund_payment_detail.html', context)