8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Vues pour gérer la liste des articles

This commit is contained in:
chirac 2016-07-06 20:57:31 +02:00
parent 387515d410
commit 6d1b41ff31
3 changed files with 53 additions and 2 deletions

View file

@ -82,3 +82,35 @@ class EditFactureForm(NewFactureForm):
self.fields['prix'].label = 'Prix unitaire'
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
self.fields.pop('article')
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = '__all__'
def __init__(self, *args, **kwargs):
super(ArticleForm, self).__init__(*args, **kwargs)
self.fields['name'].label = "Désignation de l'article"
class DelArticleForm(ModelForm):
articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
fields = ['articles']
model = Article
class PaiementForm(ModelForm):
class Meta:
model = Paiement
fields = ['moyen']
def __init__(self, *args, **kwargs):
super(PaiementForm, self).__init__(*args, **kwargs)
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
class DelPaiementForm(ModelForm):
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)
class Meta:
exclude = ['moyen']
model = Paiement

View file

@ -5,6 +5,8 @@ from . import views
urlpatterns = [
url(r'^new_facture/(?P<userid>[0-9]+)$', views.new_facture, name='new-facture'),
url(r'^edit_facture/(?P<factureid>[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'^$', views.index, name='index'),
]

View file

@ -6,9 +6,9 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.core.context_processors import csrf
from django.template import Context, RequestContext, loader
from django.contrib import messages
from django.db.models import Max
from django.db.models import Max, ProtectedError
from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article, Cotisation
from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article, Cotisation, Article, ArticleForm, DelArticleForm, Paiement, PaiementForm, DelPaiementForm
from users.models import User
from dateutil.relativedelta import relativedelta
@ -81,6 +81,23 @@ def edit_facture(request, factureid):
return redirect("/cotisations/")
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
def add_article(request):
article = ArticleForm(request.POST or None)
if article.is_valid():
article.save()
messages.success(request, "L'article a été ajouté")
return redirect("/cotisations/")
return form({'factureform': article}, 'cotisations/facture.html', request)
def del_article(request):
article = DelArticleForm(request.POST or None)
if article.is_valid():
article_del = article.cleaned_data['articles']
article_del.delete()
messages.success(request, "Le/les articles ont été supprimé")
return redirect("/cotisations/")
return form({'factureform': article}, '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})