8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 20:03:11 +00:00

Permet de gérer les banques

This commit is contained in:
chirac 2016-07-06 22:20:49 +02:00
parent 880503971b
commit 78a466808a
4 changed files with 42 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from django import forms
from django.forms import ModelForm
from .models import Article, Paiement, Facture
from .models import Article, Paiement, Facture, Banque
class NewFactureForm(ModelForm):
article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article")
@ -71,3 +71,18 @@ class DelPaiementForm(ModelForm):
exclude = ['moyen']
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

View file

@ -6,4 +6,6 @@
<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: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 %}

View file

@ -9,6 +9,8 @@ urlpatterns = [
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'^add_banque/$', views.add_banque, name='add-banque'),
url(r'^del_banque/$', views.del_banque, name='del-banque'),
url(r'^$', views.index, name='index'),
]

View file

@ -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, PaiementForm, DelPaiementForm
from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm
from users.models import User
from dateutil.relativedelta import relativedelta
@ -120,6 +120,27 @@ def del_paiement(request):
return redirect("/cotisations/")
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):
facture_list = Facture.objects.order_by('date').reverse()
return render(request, 'cotisations/index.html', {'facture_list': facture_list})