From db638966973f0318b9fb975bdf12ff168652b08d Mon Sep 17 00:00:00 2001 From: chirac Date: Wed, 6 Jul 2016 21:43:39 +0200 Subject: [PATCH] =?UTF-8?q?Permet=20de=20g=C3=A9rer=20les=20moyens=20de=20?= =?UTF-8?q?paiement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/cotisations/sidebar.html | 4 ++++ cotisations/urls.py | 2 ++ cotisations/views.py | 23 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cotisations/templates/cotisations/sidebar.html b/cotisations/templates/cotisations/sidebar.html index 0b4c5c42..6f39d00f 100644 --- a/cotisations/templates/cotisations/sidebar.html +++ b/cotisations/templates/cotisations/sidebar.html @@ -2,4 +2,8 @@ {% block sidebar %}

Liste des factures

+

Ajouter un article

+

Retirer un article

+

Ajouter un moyen de paiement

+

Retirer un moyen de paiement

{% endblock %} diff --git a/cotisations/urls.py b/cotisations/urls.py index 9e5e02a2..7589e5c1 100644 --- a/cotisations/urls.py +++ b/cotisations/urls.py @@ -7,6 +7,8 @@ urlpatterns = [ url(r'^edit_facture/(?P[0-9]+)$', views.edit_facture, name='edit-facture'), url(r'^add_article/$', views.add_article, name='add-article'), url(r'^del_article/$', views.del_article, name='del-article'), + url(r'^add_paiement/$', views.add_paiement, name='add-paiement'), + url(r'^del_paiement/$', views.del_paiement, name='del-paiement'), url(r'^$', views.index, name='index'), ] diff --git a/cotisations/views.py b/cotisations/views.py index 3d8847f6..308eb588 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -9,7 +9,7 @@ from django.contrib import messages from django.db.models import Max, ProtectedError from .models import Facture, Article, Cotisation, Article -from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, DelPaiementForm +from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm from users.models import User from dateutil.relativedelta import relativedelta @@ -99,6 +99,27 @@ def del_article(request): return redirect("/cotisations/") return form({'factureform': article}, 'cotisations/facture.html', request) +def add_paiement(request): + paiement = PaiementForm(request.POST or None) + if paiement.is_valid(): + paiement.save() + messages.success(request, "Le moyen de paiement a été ajouté") + return redirect("/cotisations/") + return form({'factureform': paiement}, 'cotisations/facture.html', request) + +def del_paiement(request): + paiement = DelPaiementForm(request.POST or None) + if paiement.is_valid(): + paiement_dels = paiement.cleaned_data['paiements'] + for paiement_del in paiement_dels: + try: + paiement_del.delete() + messages.success(request, "Le moyen de paiement a été supprimé") + except ProtectedError: + messages.error(request, "Le moyen de paiement %s est affecté à au moins une facture, vous ne pouvez pas le supprimer" % paiement_del) + return redirect("/cotisations/") + return form({'factureform': paiement}, 'cotisations/facture.html', request) + def index(request): facture_list = Facture.objects.order_by('date').reverse() return render(request, 'cotisations/index.html', {'facture_list': facture_list})