Commit 78a46680 authored by chirac's avatar chirac
Browse files

Permet de gérer les banques

parent 88050397
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
from .models import Article, Paiement, Facture from .models import Article, Paiement, Facture, Banque
class NewFactureForm(ModelForm): class NewFactureForm(ModelForm):
article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article") article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article")
...@@ -71,3 +71,18 @@ class DelPaiementForm(ModelForm): ...@@ -71,3 +71,18 @@ class DelPaiementForm(ModelForm):
exclude = ['moyen'] exclude = ['moyen']
model = Paiement model = Paiement
class BanqueForm(ModelForm):
class Meta:
model = Banque
fields = ['name']
def __init__(self, *args, **kwargs):
super(BanqueForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Banque à ajouter'
class DelBanqueForm(ModelForm):
banques = forms.ModelMultipleChoiceField(queryset=Banque.objects.all(), label="Banques actuelles", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['name']
model = Banque
...@@ -6,4 +6,6 @@ ...@@ -6,4 +6,6 @@
<p><a href="{% url "cotisations:del-article" %}">Retirer un article</a></p> <p><a href="{% url "cotisations:del-article" %}">Retirer un article</a></p>
<p><a href="{% url "cotisations:add-paiement" %}">Ajouter un moyen de paiement</a></p> <p><a href="{% url "cotisations:add-paiement" %}">Ajouter un moyen de paiement</a></p>
<p><a href="{% url "cotisations:del-paiement" %}">Retirer un moyen de paiement</a></p> <p><a href="{% url "cotisations:del-paiement" %}">Retirer un moyen de paiement</a></p>
<p><a href="{% url "cotisations:add-banque" %}">Ajouter une banque</a></p>
<p><a href="{% url "cotisations:del-banque" %}">Retirer une banque</a></p>
{% endblock %} {% endblock %}
...@@ -9,6 +9,8 @@ urlpatterns = [ ...@@ -9,6 +9,8 @@ urlpatterns = [
url(r'^del_article/$', views.del_article, name='del-article'), url(r'^del_article/$', views.del_article, name='del-article'),
url(r'^add_paiement/$', views.add_paiement, name='add-paiement'), url(r'^add_paiement/$', views.add_paiement, name='add-paiement'),
url(r'^del_paiement/$', views.del_paiement, name='del-paiement'), url(r'^del_paiement/$', views.del_paiement, name='del-paiement'),
url(r'^add_banque/$', views.add_banque, name='add-banque'),
url(r'^del_banque/$', views.del_banque, name='del-banque'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]
......
...@@ -9,7 +9,7 @@ from django.contrib import messages ...@@ -9,7 +9,7 @@ from django.contrib import messages
from django.db.models import Max, ProtectedError from django.db.models import Max, ProtectedError
from .models import Facture, Article, Cotisation, Article from .models import Facture, Article, Cotisation, Article
from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm
from users.models import User from users.models import User
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
...@@ -120,6 +120,27 @@ def del_paiement(request): ...@@ -120,6 +120,27 @@ def del_paiement(request):
return redirect("/cotisations/") return redirect("/cotisations/")
return form({'factureform': paiement}, 'cotisations/facture.html', request) return form({'factureform': paiement}, 'cotisations/facture.html', request)
def add_banque(request):
banque = BanqueForm(request.POST or None)
if banque.is_valid():
banque.save()
messages.success(request, "La banque a été ajoutée")
return redirect("/cotisations/")
return form({'factureform': banque}, 'cotisations/facture.html', request)
def del_banque(request):
banque = DelBanqueForm(request.POST or None)
if banque.is_valid():
banque_dels = banque.cleaned_data['banques']
for banque_del in banque_dels:
try:
banque_del.delete()
messages.success(request, "La banque a été supprimée")
except ProtectedError:
messages.error(request, "La banque %s est affectée à au moins une facture, vous ne pouvez pas la supprimer" % banque_del)
return redirect("/cotisations/")
return form({'factureform': banque}, 'cotisations/facture.html', request)
def index(request): def index(request):
facture_list = Facture.objects.order_by('date').reverse() facture_list = Facture.objects.order_by('date').reverse()
return render(request, 'cotisations/index.html', {'facture_list': facture_list}) return render(request, 'cotisations/index.html', {'facture_list': facture_list})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment