2016-07-02 13:58:50 +00:00
|
|
|
# App de gestion des users pour re2o
|
|
|
|
# Goulven Kermarec, Gabriel Détraz
|
|
|
|
# Gplv2
|
|
|
|
from django.shortcuts import render, redirect
|
2016-12-12 12:32:18 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from django.template.context_processors import csrf
|
2016-07-22 01:25:04 +00:00
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
2016-07-02 13:58:50 +00:00
|
|
|
from django.template import Context, RequestContext, loader
|
2016-07-09 02:12:09 +00:00
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2016-07-02 13:58:50 +00:00
|
|
|
from django.contrib import messages
|
2016-07-06 18:57:31 +00:00
|
|
|
from django.db.models import Max, ProtectedError
|
2016-07-21 14:58:12 +00:00
|
|
|
from django.db import transaction
|
2016-07-13 23:54:06 +00:00
|
|
|
from django.forms import modelformset_factory, formset_factory
|
|
|
|
import os
|
2016-07-21 14:58:12 +00:00
|
|
|
from reversion import revisions as reversion
|
2016-12-11 16:24:04 +00:00
|
|
|
from reversion.models import Version
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-07-11 20:52:55 +00:00
|
|
|
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
|
2016-07-14 20:29:30 +00:00
|
|
|
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
|
2016-07-02 15:58:04 +00:00
|
|
|
from users.models import User
|
2016-07-08 01:27:02 +00:00
|
|
|
from .tex import render_tex
|
2016-07-22 01:25:04 +00:00
|
|
|
from re2o.settings import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, PAGINATION_NUMBER
|
2016-07-13 23:54:06 +00:00
|
|
|
from re2o import settings
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-07-02 19:17:21 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
2016-07-02 19:32:00 +00:00
|
|
|
from django.utils import timezone
|
2016-07-02 19:17:21 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
def form(ctx, template, request):
|
|
|
|
c = ctx
|
|
|
|
c.update(csrf(request))
|
2016-12-12 12:32:18 +00:00
|
|
|
return render(request, template, c)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-10-26 12:05:18 +00:00
|
|
|
def create_cotis(vente, user, duration, date_start=False):
|
2016-07-02 19:17:21 +00:00
|
|
|
""" Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée"""
|
2016-07-17 18:08:56 +00:00
|
|
|
cotisation=Cotisation(vente=vente)
|
2016-11-29 22:53:02 +00:00
|
|
|
if date_start:
|
2016-12-14 02:08:57 +00:00
|
|
|
end_adhesion = Cotisation.objects.filter(vente__in=Vente.objects.filter(facture__in=Facture.objects.filter(user=user).exclude(valid=False))).filter(date_start__lt=date_start).aggregate(Max('date_end'))['date_end__max']
|
2016-11-29 22:53:02 +00:00
|
|
|
else:
|
|
|
|
end_adhesion = user.end_adhesion()
|
2016-10-26 12:05:18 +00:00
|
|
|
date_start = date_start or timezone.now()
|
2016-11-29 22:53:02 +00:00
|
|
|
end_adhesion = end_adhesion or date_start
|
|
|
|
date_max = max(end_adhesion, date_start)
|
|
|
|
cotisation.date_start = date_max
|
2016-07-05 00:22:11 +00:00
|
|
|
cotisation.date_end = cotisation.date_start + relativedelta(months=duration)
|
2016-07-02 19:17:21 +00:00
|
|
|
cotisation.save()
|
|
|
|
return
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-02 13:58:50 +00:00
|
|
|
def new_facture(request, userid):
|
2016-07-02 15:58:04 +00:00
|
|
|
try:
|
|
|
|
user = User.objects.get(pk=userid)
|
|
|
|
except User.DoesNotExist:
|
|
|
|
messages.error(request, u"Utilisateur inexistant" )
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
facture = Facture(user=user)
|
2016-07-14 18:51:45 +00:00
|
|
|
# Le template a besoin de connaitre les articles pour le js
|
|
|
|
article_list = Article.objects.all()
|
|
|
|
# On envoie la form fature et un formset d'articles
|
2016-07-02 13:58:50 +00:00
|
|
|
facture_form = NewFactureForm(request.POST or None, instance=facture)
|
2016-07-14 18:51:45 +00:00
|
|
|
article_formset = formset_factory(SelectArticleForm)(request.POST or None)
|
2016-07-14 11:55:46 +00:00
|
|
|
if facture_form.is_valid() and article_formset.is_valid():
|
2016-07-02 15:58:04 +00:00
|
|
|
new_facture = facture_form.save(commit=False)
|
2016-07-14 11:55:46 +00:00
|
|
|
articles = article_formset
|
2016-07-14 18:51:45 +00:00
|
|
|
# Si au moins un article est rempli
|
2016-07-14 11:55:46 +00:00
|
|
|
if any(art.cleaned_data for art in articles):
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
new_facture.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Création")
|
2016-07-14 11:55:46 +00:00
|
|
|
for art_item in articles:
|
|
|
|
if art_item.cleaned_data:
|
|
|
|
article = art_item.cleaned_data['article']
|
|
|
|
quantity = art_item.cleaned_data['quantity']
|
2016-07-17 18:08:56 +00:00
|
|
|
new_vente = Vente.objects.create(facture=new_facture, name=article.name, prix=article.prix, iscotisation=article.iscotisation, duration=article.duration, number=quantity)
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
new_vente.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Création")
|
2016-07-17 18:08:56 +00:00
|
|
|
if art_item.cleaned_data['article'].iscotisation:
|
|
|
|
create_cotis(new_vente, user, art_item.cleaned_data['article'].duration*art_item.cleaned_data['quantity'])
|
|
|
|
if any(art_item.cleaned_data['article'].iscotisation for art_item in articles if art_item.cleaned_data):
|
2016-07-14 18:51:45 +00:00
|
|
|
messages.success(request, "La cotisation a été prolongée pour l'adhérent %s jusqu'au %s" % (user.name, user.end_adhesion()) )
|
2016-07-14 11:55:46 +00:00
|
|
|
else:
|
|
|
|
messages.success(request, "La facture a été crée")
|
|
|
|
return redirect("/users/profil/" + userid)
|
|
|
|
messages.error(request, u"Il faut au moins un article valide pour créer une facture" )
|
2016-07-14 18:51:45 +00:00
|
|
|
return form({'factureform': facture_form, 'venteform': article_formset, 'articlelist': article_list}, 'cotisations/new_facture.html', request)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-13 23:54:06 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-08 01:27:02 +00:00
|
|
|
def new_facture_pdf(request):
|
2016-07-09 21:26:17 +00:00
|
|
|
facture_form = NewFactureFormPdf(request.POST or None)
|
|
|
|
if facture_form.is_valid():
|
|
|
|
tbl = []
|
|
|
|
article = facture_form.cleaned_data['article']
|
|
|
|
quantite = facture_form.cleaned_data['number']
|
|
|
|
paid = facture_form.cleaned_data['paid']
|
|
|
|
destinataire = facture_form.cleaned_data['dest']
|
2016-07-13 23:54:06 +00:00
|
|
|
chambre = facture_form.cleaned_data['chambre']
|
|
|
|
fid = facture_form.cleaned_data['fid']
|
2016-07-09 21:26:17 +00:00
|
|
|
for a in article:
|
|
|
|
tbl.append([a, quantite, a.prix * quantite])
|
|
|
|
prix_total = sum(a[2] for a in tbl)
|
2016-07-13 23:54:06 +00:00
|
|
|
user = {'name':destinataire, 'room':chambre}
|
|
|
|
return render_tex(request, 'cotisations/factures.tex', {'DATE' : timezone.now(),'dest':user,'fid':fid, 'article':tbl, 'total':prix_total, 'paid':paid, 'asso_name':ASSO_NAME, 'line1':ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE, 'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)})
|
2016-07-09 21:26:17 +00:00
|
|
|
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
2016-07-08 01:27:02 +00:00
|
|
|
|
2016-07-11 22:05:07 +00:00
|
|
|
@login_required
|
|
|
|
def facture_pdf(request, factureid):
|
|
|
|
try:
|
|
|
|
facture = Facture.objects.get(pk=factureid)
|
|
|
|
except Facture.DoesNotExist:
|
|
|
|
messages.error(request, u"Facture inexistante" )
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
if not request.user.has_perms(('cableur',)) and facture.user != request.user:
|
|
|
|
messages.error(request, "Vous ne pouvez pas afficher une facture ne vous appartenant pas sans droit cableur")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
2016-07-14 20:29:30 +00:00
|
|
|
if not facture.valid:
|
|
|
|
messages.error(request, "Vous ne pouvez pas afficher une facture non valide")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
2016-07-11 22:05:07 +00:00
|
|
|
vente = Vente.objects.all().filter(facture=facture)
|
|
|
|
ventes = []
|
|
|
|
for v in vente:
|
2016-07-13 23:54:06 +00:00
|
|
|
ventes.append([v, v.number, v.prix_total])
|
|
|
|
return render_tex(request, 'cotisations/factures.tex', {'paid':True, 'fid':facture.id, 'DATE':facture.date,'dest':facture.user, 'article':ventes, 'total': facture.prix_total(), 'asso_name':ASSO_NAME, 'line1': ASSO_ADDRESS_LINE1, 'line2':ASSO_ADDRESS_LINE2, 'siret':ASSO_SIRET, 'email':ASSO_EMAIL, 'phone':ASSO_PHONE, 'tpl_path':os.path.join(settings.BASE_DIR, LOGO_PATH)})
|
2016-07-11 22:05:07 +00:00
|
|
|
|
2016-07-13 23:54:06 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-02 13:58:50 +00:00
|
|
|
def edit_facture(request, factureid):
|
|
|
|
try:
|
|
|
|
facture = Facture.objects.get(pk=factureid)
|
|
|
|
except Facture.DoesNotExist:
|
|
|
|
messages.error(request, u"Facture inexistante" )
|
|
|
|
return redirect("/cotisations/")
|
2016-07-14 20:29:30 +00:00
|
|
|
if request.user.has_perms(['trésorier']):
|
|
|
|
facture_form = TrezEditFactureForm(request.POST or None, instance=facture)
|
|
|
|
elif facture.control or not facture.valid:
|
|
|
|
messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
else:
|
|
|
|
facture_form = EditFactureForm(request.POST or None, instance=facture)
|
2016-07-13 23:54:06 +00:00
|
|
|
ventes_objects = Vente.objects.filter(facture=facture)
|
2016-07-14 18:51:45 +00:00
|
|
|
vente_form_set = modelformset_factory(Vente, fields=('name','number'), extra=0, max_num=len(ventes_objects))
|
2016-07-13 23:54:06 +00:00
|
|
|
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
|
|
|
|
if facture_form.is_valid() and vente_form.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
facture_form.save()
|
|
|
|
vente_form.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for form in vente_form for field in facture_form.changed_data + form.changed_data))
|
2016-07-02 13:58:50 +00:00
|
|
|
messages.success(request, "La facture a bien été modifiée")
|
|
|
|
return redirect("/cotisations/")
|
2016-07-17 19:20:43 +00:00
|
|
|
return form({'factureform': facture_form, 'venteform': vente_form}, 'cotisations/edit_facture.html', request)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-07-14 20:29:30 +00:00
|
|
|
@login_required
|
|
|
|
@permission_required('cableur')
|
|
|
|
def del_facture(request, factureid):
|
|
|
|
try:
|
|
|
|
facture = Facture.objects.get(pk=factureid)
|
|
|
|
except Facture.DoesNotExist:
|
|
|
|
messages.error(request, u"Facture inexistante" )
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
if (facture.control or not facture.valid):
|
|
|
|
messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
|
|
|
|
return redirect("/cotisations/")
|
2016-07-18 16:37:52 +00:00
|
|
|
if request.method == "POST":
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
facture.delete()
|
|
|
|
reversion.set_user(request.user)
|
2016-07-18 16:37:52 +00:00
|
|
|
messages.success(request, "La facture a été détruite")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
return form({'objet': facture, 'objet_name': 'facture'}, 'cotisations/delete.html', request)
|
2016-07-14 20:29:30 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-06 18:57:31 +00:00
|
|
|
def add_article(request):
|
|
|
|
article = ArticleForm(request.POST or None)
|
|
|
|
if article.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
article.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Création")
|
2016-07-06 18:57:31 +00:00
|
|
|
messages.success(request, "L'article a été ajouté")
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_article/")
|
|
|
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-08 01:27:02 +00:00
|
|
|
def edit_article(request, articleid):
|
|
|
|
try:
|
|
|
|
article_instance = Article.objects.get(pk=articleid)
|
|
|
|
except Article.DoesNotExist:
|
|
|
|
messages.error(request, u"Entrée inexistante" )
|
|
|
|
return redirect("/cotisations/index_article/")
|
|
|
|
article = ArticleForm(request.POST or None, instance=article_instance)
|
|
|
|
if article.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
article.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in article.changed_data))
|
2016-07-08 01:27:02 +00:00
|
|
|
messages.success(request, "Type d'article modifié")
|
|
|
|
return redirect("/cotisations/index_article/")
|
2016-07-06 18:57:31 +00:00
|
|
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-06 18:57:31 +00:00
|
|
|
def del_article(request):
|
|
|
|
article = DelArticleForm(request.POST or None)
|
|
|
|
if article.is_valid():
|
|
|
|
article_del = article.cleaned_data['articles']
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
article_del.delete()
|
|
|
|
reversion.set_user(request.user)
|
2016-07-06 18:57:31 +00:00
|
|
|
messages.success(request, "Le/les articles ont été supprimé")
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_article")
|
2016-07-06 18:57:31 +00:00
|
|
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-06 19:43:39 +00:00
|
|
|
def add_paiement(request):
|
|
|
|
paiement = PaiementForm(request.POST or None)
|
|
|
|
if paiement.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
paiement.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Création")
|
2016-07-06 19:43:39 +00:00
|
|
|
messages.success(request, "Le moyen de paiement a été ajouté")
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_paiement/")
|
|
|
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-08 01:27:02 +00:00
|
|
|
def edit_paiement(request, paiementid):
|
|
|
|
try:
|
|
|
|
paiement_instance = Paiement.objects.get(pk=paiementid)
|
|
|
|
except Paiement.DoesNotExist:
|
|
|
|
messages.error(request, u"Entrée inexistante" )
|
|
|
|
return redirect("/cotisations/index_paiement/")
|
|
|
|
paiement = PaiementForm(request.POST or None, instance=paiement_instance)
|
|
|
|
if paiement.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
paiement.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in paiement.changed_data))
|
2016-07-08 01:27:02 +00:00
|
|
|
messages.success(request, "Type de paiement modifié")
|
|
|
|
return redirect("/cotisations/index_paiement/")
|
2016-07-06 19:43:39 +00:00
|
|
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-06 19:43:39 +00:00
|
|
|
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:
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
paiement_del.delete()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Destruction")
|
2016-07-06 19:43:39 +00:00
|
|
|
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)
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_paiement/")
|
2016-07-06 19:43:39 +00:00
|
|
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-06 20:20:49 +00:00
|
|
|
def add_banque(request):
|
|
|
|
banque = BanqueForm(request.POST or None)
|
|
|
|
if banque.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
banque.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Création")
|
2016-07-06 20:20:49 +00:00
|
|
|
messages.success(request, "La banque a été ajoutée")
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_banque/")
|
|
|
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-08 01:27:02 +00:00
|
|
|
def edit_banque(request, banqueid):
|
|
|
|
try:
|
2016-07-17 19:20:43 +00:00
|
|
|
banque_instance = Banque.objects.get(pk=banqueid)
|
2016-07-08 01:27:02 +00:00
|
|
|
except Banque.DoesNotExist:
|
|
|
|
messages.error(request, u"Entrée inexistante" )
|
|
|
|
return redirect("/cotisations/index_banque/")
|
|
|
|
banque = BanqueForm(request.POST or None, instance=banque_instance)
|
|
|
|
if banque.is_valid():
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
banque.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in banque.changed_data))
|
2016-07-08 01:27:02 +00:00
|
|
|
messages.success(request, "Banque modifiée")
|
|
|
|
return redirect("/cotisations/index_banque/")
|
2016-07-06 20:20:49 +00:00
|
|
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 02:12:09 +00:00
|
|
|
@permission_required('trésorier')
|
2016-07-06 20:20:49 +00:00
|
|
|
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:
|
2016-07-21 14:58:12 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
banque_del.delete()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Destruction")
|
2016-07-06 20:20:49 +00:00
|
|
|
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)
|
2016-07-08 01:27:02 +00:00
|
|
|
return redirect("/cotisations/index_banque/")
|
2016-07-06 20:20:49 +00:00
|
|
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
|
|
|
|
2016-07-17 18:08:56 +00:00
|
|
|
@login_required
|
|
|
|
@permission_required('trésorier')
|
|
|
|
def control(request):
|
|
|
|
facture_list = Facture.objects.order_by('date').reverse()
|
|
|
|
controlform_set = modelformset_factory(Facture, fields=('control','valid'), extra=0)
|
2016-11-18 10:31:33 +00:00
|
|
|
paginator = Paginator(facture_list, PAGINATION_NUMBER)
|
|
|
|
page = request.GET.get('page')
|
|
|
|
try:
|
|
|
|
facture_list = paginator.page(page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
facture_list = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
facture_list = paginator.page(paginator.num.pages)
|
|
|
|
page_query = Facture.objects.order_by('date').reverse().filter(id__in=[facture.id for facture in facture_list])
|
|
|
|
controlform = controlform_set(request.POST or None, queryset=page_query)
|
2016-07-17 18:08:56 +00:00
|
|
|
if controlform.is_valid():
|
2016-12-14 02:08:57 +00:00
|
|
|
with transaction.atomic(), reversion.create_revision():
|
|
|
|
controlform.save()
|
|
|
|
reversion.set_user(request.user)
|
|
|
|
reversion.set_comment("Controle trésorier")
|
2016-07-17 18:08:56 +00:00
|
|
|
return redirect("/cotisations/control/")
|
2016-11-18 10:31:33 +00:00
|
|
|
return render(request, 'cotisations/control.html', {'facture_list': facture_list, 'controlform': controlform})
|
2016-07-17 18:08:56 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-08 01:27:02 +00:00
|
|
|
def index_article(request):
|
|
|
|
article_list = Article.objects.order_by('name')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'cotisations/index_article.html', {'article_list':article_list})
|
2016-07-08 01:27:02 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-08 01:27:02 +00:00
|
|
|
def index_paiement(request):
|
|
|
|
paiement_list = Paiement.objects.order_by('moyen')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'cotisations/index_paiement.html', {'paiement_list':paiement_list})
|
2016-07-08 01:27:02 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-08 01:27:02 +00:00
|
|
|
def index_banque(request):
|
|
|
|
banque_list = Banque.objects.order_by('name')
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'cotisations/index_banque.html', {'banque_list':banque_list})
|
2016-07-08 01:27:02 +00:00
|
|
|
|
2016-07-08 10:35:53 +00:00
|
|
|
@login_required
|
2016-07-09 15:16:44 +00:00
|
|
|
@permission_required('cableur')
|
2016-07-02 13:58:50 +00:00
|
|
|
def index(request):
|
2016-07-05 14:19:17 +00:00
|
|
|
facture_list = Facture.objects.order_by('date').reverse()
|
2016-07-22 01:25:04 +00:00
|
|
|
paginator = Paginator(facture_list, PAGINATION_NUMBER)
|
|
|
|
page = request.GET.get('page')
|
|
|
|
try:
|
|
|
|
facture_list = paginator.page(page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
# If page is not an integer, deliver first page.
|
|
|
|
facture_list = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
|
|
|
facture_list = paginator.page(paginator.num_pages)
|
2016-07-10 02:02:48 +00:00
|
|
|
return render(request, 'cotisations/index.html', {'facture_list': facture_list})
|
2016-07-21 14:58:12 +00:00
|
|
|
|
|
|
|
@login_required
|
|
|
|
def history(request, object, id):
|
|
|
|
if object == 'facture':
|
|
|
|
try:
|
|
|
|
object_instance = Facture.objects.get(pk=id)
|
|
|
|
except Facture.DoesNotExist:
|
|
|
|
messages.error(request, "Facture inexistante")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
if not request.user.has_perms(('cableur',)) and object_instance.user != request.user:
|
|
|
|
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit cableur")
|
|
|
|
return redirect("/users/profil/" + str(request.user.id))
|
|
|
|
elif object == 'paiement' and request.user.has_perms(('cableur',)):
|
|
|
|
try:
|
|
|
|
object_instance = Paiement.objects.get(pk=id)
|
|
|
|
except Paiement.DoesNotExist:
|
|
|
|
messages.error(request, "Paiement inexistant")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
elif object == 'article' and request.user.has_perms(('cableur',)):
|
|
|
|
try:
|
|
|
|
object_instance = Article.objects.get(pk=id)
|
|
|
|
except Article.DoesNotExist:
|
|
|
|
messages.error(request, "Article inexistante")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
elif object == 'banque' and request.user.has_perms(('cableur',)):
|
|
|
|
try:
|
|
|
|
object_instance = Banque.objects.get(pk=id)
|
|
|
|
except Banque.DoesNotExist:
|
|
|
|
messages.error(request, "Banque inexistante")
|
|
|
|
return redirect("/cotisations/")
|
|
|
|
else:
|
|
|
|
messages.error(request, "Objet inconnu")
|
|
|
|
return redirect("/cotisations/")
|
2016-12-11 16:24:04 +00:00
|
|
|
reversions = Version.objects.get_for_object(object_instance)
|
2016-07-27 01:36:28 +00:00
|
|
|
paginator = Paginator(reversions, PAGINATION_NUMBER)
|
|
|
|
page = request.GET.get('page')
|
|
|
|
try:
|
|
|
|
reversions = paginator.page(page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
# If page is not an integer, deliver first page.
|
|
|
|
reversions = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
|
|
|
reversions = paginator.page(paginator.num_pages)
|
2016-07-21 14:58:12 +00:00
|
|
|
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
|