Add ability to add payment

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

View file

@ -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"
}
),
}

View file

@ -2,6 +2,15 @@
{% load l10n %} {% load l10n %}
{% block content %} {% block content %}
<h1>{% block title %}Payments to refund{% endblock %}</h1> <h1>
{% block title %}Payments to refund{% endblock %}
{% if user.is_authenticated %}
<div class="btn-group pull-right">
<a class="btn btn-success" href="{% url 'new_payment' %}">
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
{% endif %}
</h1>
{% include 'refunding/elements_list.html' with elements=payments %} {% include 'refunding/elements_list.html' with elements=payments %}
{% endblock %} {% endblock %}

View file

@ -5,5 +5,6 @@ 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'^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]+)/edit/$', views.refund_edit, name='refund_edit'),
] ]

View file

@ -1,7 +1,7 @@
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, get_object_or_404 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 from refunding.models import Payment, Refund
@ -48,7 +48,27 @@ def new_refund(request):
'form': form, 'form': form,
'title': 'New refund' '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 @login_required
@ -67,4 +87,4 @@ def refund_edit(request, pk):
'form': form, 'form': form,
'title': 'Edit refund' 'title': 'Edit refund'
} }
return render(request, 'refunding/edit_new_refund.html', context) return render(request, 'refunding/refund_payment_detail.html', context)