mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 15:12:25 +00:00
PEP8 et doc strings sur views de cotisations
This commit is contained in:
parent
993aeb31c8
commit
500884458c
1 changed files with 259 additions and 64 deletions
|
@ -40,7 +40,10 @@ from reversion import revisions as reversion
|
||||||
from reversion.models import Version
|
from reversion.models import Version
|
||||||
|
|
||||||
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
|
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
|
||||||
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, CreditSoldeForm, SelectArticleForm
|
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
|
||||||
|
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm
|
||||||
|
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf
|
||||||
|
from .forms import SelectArticleForm, CreditSoldeForm
|
||||||
from users.models import User
|
from users.models import User
|
||||||
from .tex import render_tex
|
from .tex import render_tex
|
||||||
from re2o.settings import LOGO_PATH
|
from re2o.settings import LOGO_PATH
|
||||||
|
@ -50,18 +53,27 @@ from preferences.models import OptionalUser, AssoOption, GeneralOption
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
c = ctx
|
||||||
c.update(csrf(request))
|
c.update(csrf(request))
|
||||||
return render(request, template, c)
|
return render(request, template, c)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def new_facture(request, userid):
|
def new_facture(request, userid):
|
||||||
|
"""Creation d'une facture pour un user. Renvoie la liste des articles
|
||||||
|
et crée des factures dans un formset. Utilise un peu de js coté template
|
||||||
|
pour ajouter des articles.
|
||||||
|
Parse les article et boucle dans le formset puis save les ventes,
|
||||||
|
enfin sauve la facture parente.
|
||||||
|
TODO : simplifier cette fonction, déplacer l'intelligence coté models
|
||||||
|
Facture et Vente."""
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(pk=userid)
|
user = User.objects.get(pk=userid)
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
messages.error(request, u"Utilisateur inexistant" )
|
messages.error(request, u"Utilisateur inexistant")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
facture = Facture(user=user)
|
facture = Facture(user=user)
|
||||||
# Le template a besoin de connaitre les articles pour le js
|
# Le template a besoin de connaitre les articles pour le js
|
||||||
|
@ -77,15 +89,20 @@ def new_facture(request, userid):
|
||||||
options, created = OptionalUser.objects.get_or_create()
|
options, created = OptionalUser.objects.get_or_create()
|
||||||
user_solde = options.user_solde
|
user_solde = options.user_solde
|
||||||
solde_negatif = options.solde_negatif
|
solde_negatif = options.solde_negatif
|
||||||
# Si on paye par solde, que l'option est activée, on vérifie que le négatif n'est pas atteint
|
# Si on paye par solde, que l'option est activée,
|
||||||
|
# on vérifie que le négatif n'est pas atteint
|
||||||
if user_solde:
|
if user_solde:
|
||||||
if new_facture.paiement == Paiement.objects.get_or_create(moyen='solde')[0]:
|
if new_facture.paiement == Paiement.objects.get_or_create(
|
||||||
|
moyen='solde'
|
||||||
|
)[0]:
|
||||||
prix_total = 0
|
prix_total = 0
|
||||||
for art_item in articles:
|
for art_item in articles:
|
||||||
if art_item.cleaned_data:
|
if art_item.cleaned_data:
|
||||||
prix_total += art_item.cleaned_data['article'].prix*art_item.cleaned_data['quantity']
|
prix_total += art_item.cleaned_data['article']\
|
||||||
|
.prix*art_item.cleaned_data['quantity']
|
||||||
if float(user.solde) - float(prix_total) < solde_negatif:
|
if float(user.solde) - float(prix_total) < solde_negatif:
|
||||||
messages.error(request, "Le solde est insuffisant pour effectuer l'opération")
|
messages.error(request, "Le solde est insuffisant pour\
|
||||||
|
effectuer l'opération")
|
||||||
return redirect("/users/profil/" + userid)
|
return redirect("/users/profil/" + userid)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_facture.save()
|
new_facture.save()
|
||||||
|
@ -95,22 +112,47 @@ def new_facture(request, userid):
|
||||||
if art_item.cleaned_data:
|
if art_item.cleaned_data:
|
||||||
article = art_item.cleaned_data['article']
|
article = art_item.cleaned_data['article']
|
||||||
quantity = art_item.cleaned_data['quantity']
|
quantity = art_item.cleaned_data['quantity']
|
||||||
new_vente = Vente.objects.create(facture=new_facture, name=article.name, prix=article.prix, iscotisation=article.iscotisation, duration=article.duration, number=quantity)
|
new_vente = Vente.objects.create(
|
||||||
|
facture=new_facture,
|
||||||
|
name=article.name,
|
||||||
|
prix=article.prix,
|
||||||
|
iscotisation=article.iscotisation,
|
||||||
|
duration=article.duration,
|
||||||
|
number=quantity
|
||||||
|
)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_vente.save()
|
new_vente.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Création")
|
reversion.set_comment("Création")
|
||||||
if any(art_item.cleaned_data['article'].iscotisation for art_item in articles if art_item.cleaned_data):
|
if any(art_item.cleaned_data['article'].iscotisation
|
||||||
messages.success(request, "La cotisation a été prolongée pour l'adhérent %s jusqu'au %s" % (user.pseudo, user.end_adhesion()) )
|
for art_item in articles if art_item.cleaned_data):
|
||||||
|
messages.success(
|
||||||
|
request,
|
||||||
|
"La cotisation a été prolongée\
|
||||||
|
pour l'adhérent %s jusqu'au %s" % (
|
||||||
|
user.pseudo, user.end_adhesion()
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
messages.success(request, "La facture a été crée")
|
messages.success(request, "La facture a été crée")
|
||||||
return redirect("/users/profil/" + userid)
|
return redirect("/users/profil/" + userid)
|
||||||
messages.error(request, u"Il faut au moins un article valide pour créer une facture" )
|
messages.error(
|
||||||
return form({'factureform': facture_form, 'venteform': article_formset, 'articlelist': article_list}, 'cotisations/new_facture.html', request)
|
request,
|
||||||
|
u"Il faut au moins un article valide pour créer une facture"
|
||||||
|
)
|
||||||
|
return form({
|
||||||
|
'factureform': facture_form,
|
||||||
|
'venteform': article_formset,
|
||||||
|
'articlelist': article_list
|
||||||
|
}, 'cotisations/new_facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def new_facture_pdf(request):
|
def new_facture_pdf(request):
|
||||||
|
"""Permet de générer un pdf d'une facture. Réservée
|
||||||
|
au trésorier, permet d'emettre des factures sans objet
|
||||||
|
Vente ou Facture correspondant en bdd"""
|
||||||
facture_form = NewFactureFormPdf(request.POST or None)
|
facture_form = NewFactureFormPdf(request.POST or None)
|
||||||
if facture_form.is_valid():
|
if facture_form.is_valid():
|
||||||
options, created = AssoOption.objects.get_or_create()
|
options, created = AssoOption.objects.get_or_create()
|
||||||
|
@ -124,68 +166,129 @@ def new_facture_pdf(request):
|
||||||
for a in article:
|
for a in article:
|
||||||
tbl.append([a, quantite, a.prix * quantite])
|
tbl.append([a, quantite, a.prix * quantite])
|
||||||
prix_total = sum(a[2] for a in tbl)
|
prix_total = sum(a[2] for a in tbl)
|
||||||
user = {'name':destinataire, 'room':chambre}
|
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':options.name, 'line1':options.adresse1, 'line2':options.adresse2, 'siret':options.siret, 'email':options.contact, 'phone':options.telephone, 'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)})
|
return render_tex(request, 'cotisations/factures.tex', {
|
||||||
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
'DATE': timezone.now(),
|
||||||
|
'dest': user,
|
||||||
|
'fid': fid,
|
||||||
|
'article': tbl,
|
||||||
|
'total': prix_total,
|
||||||
|
'paid': paid,
|
||||||
|
'asso_name': options.name,
|
||||||
|
'line1': options.adresse1,
|
||||||
|
'line2': options.adresse2,
|
||||||
|
'siret': options.siret,
|
||||||
|
'email': options.contact,
|
||||||
|
'phone': options.telephone,
|
||||||
|
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
||||||
|
})
|
||||||
|
return form({
|
||||||
|
'factureform': facture_form
|
||||||
|
}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def facture_pdf(request, factureid):
|
def facture_pdf(request, factureid):
|
||||||
|
"""Affiche en pdf une facture. Cree une ligne par Vente de la facture,
|
||||||
|
et génére une facture avec le total, le moyen de paiement, l'adresse
|
||||||
|
de l'adhérent, etc. Réservée à self pour un user sans droits,
|
||||||
|
les droits cableurs permettent d'afficher toute facture"""
|
||||||
try:
|
try:
|
||||||
facture = Facture.objects.get(pk=factureid)
|
facture = Facture.objects.get(pk=factureid)
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
messages.error(request, u"Facture inexistante" )
|
messages.error(request, u"Facture inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
if not request.user.has_perms(('cableur',)) and facture.user != request.user:
|
if not request.user.has_perms(('cableur',))\
|
||||||
messages.error(request, "Vous ne pouvez pas afficher une facture ne vous appartenant pas sans droit 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))
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
if not facture.valid:
|
if not facture.valid:
|
||||||
messages.error(request, "Vous ne pouvez pas afficher une facture non valide")
|
messages.error(request, "Vous ne pouvez pas afficher\
|
||||||
|
une facture non valide")
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
return redirect("/users/profil/" + str(request.user.id))
|
||||||
vente = Vente.objects.all().filter(facture=facture)
|
vente = Vente.objects.all().filter(facture=facture)
|
||||||
ventes = []
|
ventes = []
|
||||||
options, created = AssoOption.objects.get_or_create()
|
options, created = AssoOption.objects.get_or_create()
|
||||||
for v in vente:
|
for v in vente:
|
||||||
ventes.append([v, v.number, v.prix_total])
|
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':options.name, 'line1': options.adresse1, 'line2':options.adresse2, 'siret':options.siret, 'email':options.contact, 'phone':options.telephone, 'tpl_path':os.path.join(settings.BASE_DIR, LOGO_PATH)})
|
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': options.name,
|
||||||
|
'line1': options.adresse1,
|
||||||
|
'line2': options.adresse2,
|
||||||
|
'siret': options.siret,
|
||||||
|
'email': options.contact,
|
||||||
|
'phone': options.telephone,
|
||||||
|
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def edit_facture(request, factureid):
|
def edit_facture(request, factureid):
|
||||||
|
"""Permet l'édition d'une facture. On peut y éditer les ventes
|
||||||
|
déjà effectuer, ou rendre une facture invalide (non payées, chèque
|
||||||
|
en bois etc). Mets à jour les durée de cotisation attenantes"""
|
||||||
try:
|
try:
|
||||||
facture = Facture.objects.get(pk=factureid)
|
facture = Facture.objects.get(pk=factureid)
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
messages.error(request, u"Facture inexistante" )
|
messages.error(request, u"Facture inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
if request.user.has_perms(['tresorier']):
|
if request.user.has_perms(['tresorier']):
|
||||||
facture_form = TrezEditFactureForm(request.POST or None, instance=facture)
|
facture_form = TrezEditFactureForm(
|
||||||
|
request.POST or None,
|
||||||
|
instance=facture
|
||||||
|
)
|
||||||
elif facture.control or not facture.valid:
|
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")
|
messages.error(request, "Vous ne pouvez pas editer une facture\
|
||||||
|
controlée ou invalidée par le trésorier")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
else:
|
else:
|
||||||
facture_form = EditFactureForm(request.POST or None, instance=facture)
|
facture_form = EditFactureForm(request.POST or None, instance=facture)
|
||||||
ventes_objects = Vente.objects.filter(facture=facture)
|
ventes_objects = Vente.objects.filter(facture=facture)
|
||||||
vente_form_set = modelformset_factory(Vente, fields=('name','number'), extra=0, max_num=len(ventes_objects))
|
vente_form_set = modelformset_factory(
|
||||||
|
Vente,
|
||||||
|
fields=('name', 'number'),
|
||||||
|
extra=0,
|
||||||
|
max_num=len(ventes_objects)
|
||||||
|
)
|
||||||
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
|
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
|
||||||
if facture_form.is_valid() and vente_form.is_valid():
|
if facture_form.is_valid() and vente_form.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
facture_form.save()
|
facture_form.save()
|
||||||
vente_form.save()
|
vente_form.save()
|
||||||
reversion.set_user(request.user)
|
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))
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
||||||
|
field for form in vente_form for field
|
||||||
|
in facture_form.changed_data + form.changed_data)
|
||||||
|
)
|
||||||
messages.success(request, "La facture a bien été modifiée")
|
messages.success(request, "La facture a bien été modifiée")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
return form({'factureform': facture_form, 'venteform': vente_form}, 'cotisations/edit_facture.html', request)
|
return form({
|
||||||
|
'factureform': facture_form,
|
||||||
|
'venteform': vente_form
|
||||||
|
}, 'cotisations/edit_facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def del_facture(request, factureid):
|
def del_facture(request, factureid):
|
||||||
|
"""Suppression d'une facture. Supprime en cascade les ventes
|
||||||
|
et cotisations filles"""
|
||||||
try:
|
try:
|
||||||
facture = Facture.objects.get(pk=factureid)
|
facture = Facture.objects.get(pk=factureid)
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
messages.error(request, u"Facture inexistante" )
|
messages.error(request, u"Facture inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
if (facture.control or not facture.valid):
|
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")
|
messages.error(request, "Vous ne pouvez pas editer une facture\
|
||||||
|
controlée ou invalidée par le trésorier")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -193,7 +296,11 @@ def del_facture(request, factureid):
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
messages.success(request, "La facture a été détruite")
|
messages.success(request, "La facture a été détruite")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
return form({'objet': facture, 'objet_name': 'facture'}, 'cotisations/delete.html', request)
|
return form({
|
||||||
|
'objet': facture,
|
||||||
|
'objet_name': 'facture'
|
||||||
|
}, 'cotisations/delete.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
|
@ -202,7 +309,7 @@ def credit_solde(request, userid):
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(pk=userid)
|
user = User.objects.get(pk=userid)
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
messages.error(request, u"Utilisateur inexistant" )
|
messages.error(request, u"Utilisateur inexistant")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
facture = CreditSoldeForm(request.POST or None)
|
facture = CreditSoldeForm(request.POST or None)
|
||||||
if facture.is_valid():
|
if facture.is_valid():
|
||||||
|
@ -212,7 +319,14 @@ def credit_solde(request, userid):
|
||||||
facture_instance.save()
|
facture_instance.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Création")
|
reversion.set_comment("Création")
|
||||||
new_vente = Vente.objects.create(facture=facture_instance, name="solde", prix=facture.cleaned_data['montant'], iscotisation=False, duration=0, number=1)
|
new_vente = Vente.objects.create(
|
||||||
|
facture=facture_instance,
|
||||||
|
name="solde",
|
||||||
|
prix=facture.cleaned_data['montant'],
|
||||||
|
iscotisation=False,
|
||||||
|
duration=0,
|
||||||
|
number=1
|
||||||
|
)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_vente.save()
|
new_vente.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
|
@ -225,6 +339,13 @@ def credit_solde(request, userid):
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def add_article(request):
|
def add_article(request):
|
||||||
|
"""Ajoute un article. Champs : désignation,
|
||||||
|
prix, est-ce une cotisation et si oui sa durée
|
||||||
|
Réservé au trésorier
|
||||||
|
Nota bene : les ventes déjà effectuées ne sont pas reliées
|
||||||
|
aux articles en vente. La désignation, le prix... sont
|
||||||
|
copiés à la création de la facture. Un changement de prix n'a
|
||||||
|
PAS de conséquence sur les ventes déjà faites"""
|
||||||
article = ArticleForm(request.POST or None)
|
article = ArticleForm(request.POST or None)
|
||||||
if article.is_valid():
|
if article.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -235,27 +356,36 @@ def add_article(request):
|
||||||
return redirect("/cotisations/index_article/")
|
return redirect("/cotisations/index_article/")
|
||||||
return form({'factureform': article}, 'cotisations/facture.html', request)
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def edit_article(request, articleid):
|
def edit_article(request, articleid):
|
||||||
|
"""Edition d'un article (designation, prix, etc)
|
||||||
|
Réservé au trésorier"""
|
||||||
try:
|
try:
|
||||||
article_instance = Article.objects.get(pk=articleid)
|
article_instance = Article.objects.get(pk=articleid)
|
||||||
except Article.DoesNotExist:
|
except Article.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante" )
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect("/cotisations/index_article/")
|
return redirect("/cotisations/index_article/")
|
||||||
article = ArticleForm(request.POST or None, instance=article_instance)
|
article = ArticleForm(request.POST or None, instance=article_instance)
|
||||||
if article.is_valid():
|
if article.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
article.save()
|
article.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in article.changed_data))
|
reversion.set_comment(
|
||||||
|
"Champs modifié(s) : %s" % ', '.join(
|
||||||
|
field for field in article.changed_data
|
||||||
|
)
|
||||||
|
)
|
||||||
messages.success(request, "Type d'article modifié")
|
messages.success(request, "Type d'article modifié")
|
||||||
return redirect("/cotisations/index_article/")
|
return redirect("/cotisations/index_article/")
|
||||||
return form({'factureform': article}, 'cotisations/facture.html', request)
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def del_article(request):
|
def del_article(request):
|
||||||
|
"""Suppression d'un article en vente"""
|
||||||
article = DelArticleForm(request.POST or None)
|
article = DelArticleForm(request.POST or None)
|
||||||
if article.is_valid():
|
if article.is_valid():
|
||||||
article_del = article.cleaned_data['articles']
|
article_del = article.cleaned_data['articles']
|
||||||
|
@ -266,9 +396,12 @@ def del_article(request):
|
||||||
return redirect("/cotisations/index_article")
|
return redirect("/cotisations/index_article")
|
||||||
return form({'factureform': article}, 'cotisations/facture.html', request)
|
return form({'factureform': article}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def add_paiement(request):
|
def add_paiement(request):
|
||||||
|
"""Ajoute un moyen de paiement. Relié aux factures
|
||||||
|
via foreign key"""
|
||||||
paiement = PaiementForm(request.POST or None)
|
paiement = PaiementForm(request.POST or None)
|
||||||
if paiement.is_valid():
|
if paiement.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -279,27 +412,35 @@ def add_paiement(request):
|
||||||
return redirect("/cotisations/index_paiement/")
|
return redirect("/cotisations/index_paiement/")
|
||||||
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def edit_paiement(request, paiementid):
|
def edit_paiement(request, paiementid):
|
||||||
|
"""Edition d'un moyen de paiement"""
|
||||||
try:
|
try:
|
||||||
paiement_instance = Paiement.objects.get(pk=paiementid)
|
paiement_instance = Paiement.objects.get(pk=paiementid)
|
||||||
except Paiement.DoesNotExist:
|
except Paiement.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante" )
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect("/cotisations/index_paiement/")
|
return redirect("/cotisations/index_paiement/")
|
||||||
paiement = PaiementForm(request.POST or None, instance=paiement_instance)
|
paiement = PaiementForm(request.POST or None, instance=paiement_instance)
|
||||||
if paiement.is_valid():
|
if paiement.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
paiement.save()
|
paiement.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in paiement.changed_data))
|
reversion.set_comment(
|
||||||
|
"Champs modifié(s) : %s" % ', '.join(
|
||||||
|
field for field in paiement.changed_data
|
||||||
|
)
|
||||||
|
)
|
||||||
messages.success(request, "Type de paiement modifié")
|
messages.success(request, "Type de paiement modifié")
|
||||||
return redirect("/cotisations/index_paiement/")
|
return redirect("/cotisations/index_paiement/")
|
||||||
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def del_paiement(request):
|
def del_paiement(request):
|
||||||
|
"""Suppression d'un moyen de paiement"""
|
||||||
paiement = DelPaiementForm(request.POST or None)
|
paiement = DelPaiementForm(request.POST or None)
|
||||||
if paiement.is_valid():
|
if paiement.is_valid():
|
||||||
paiement_dels = paiement.cleaned_data['paiements']
|
paiement_dels = paiement.cleaned_data['paiements']
|
||||||
|
@ -309,15 +450,24 @@ def del_paiement(request):
|
||||||
paiement_del.delete()
|
paiement_del.delete()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Destruction")
|
reversion.set_comment("Destruction")
|
||||||
messages.success(request, "Le moyen de paiement a été supprimé")
|
messages.success(
|
||||||
|
request,
|
||||||
|
"Le moyen de paiement a été supprimé"
|
||||||
|
)
|
||||||
except ProtectedError:
|
except ProtectedError:
|
||||||
messages.error(request, "Le moyen de paiement %s est affecté à au moins une facture, vous ne pouvez pas le supprimer" % paiement_del)
|
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/index_paiement/")
|
return redirect("/cotisations/index_paiement/")
|
||||||
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
return form({'factureform': paiement}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def add_banque(request):
|
def add_banque(request):
|
||||||
|
"""Ajoute une banque à la liste des banques"""
|
||||||
banque = BanqueForm(request.POST or None)
|
banque = BanqueForm(request.POST or None)
|
||||||
if banque.is_valid():
|
if banque.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -328,27 +478,35 @@ def add_banque(request):
|
||||||
return redirect("/cotisations/index_banque/")
|
return redirect("/cotisations/index_banque/")
|
||||||
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def edit_banque(request, banqueid):
|
def edit_banque(request, banqueid):
|
||||||
|
"""Edite le nom d'une banque"""
|
||||||
try:
|
try:
|
||||||
banque_instance = Banque.objects.get(pk=banqueid)
|
banque_instance = Banque.objects.get(pk=banqueid)
|
||||||
except Banque.DoesNotExist:
|
except Banque.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante" )
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect("/cotisations/index_banque/")
|
return redirect("/cotisations/index_banque/")
|
||||||
banque = BanqueForm(request.POST or None, instance=banque_instance)
|
banque = BanqueForm(request.POST or None, instance=banque_instance)
|
||||||
if banque.is_valid():
|
if banque.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
banque.save()
|
banque.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in banque.changed_data))
|
reversion.set_comment(
|
||||||
|
"Champs modifié(s) : %s" % ', '.join(
|
||||||
|
field for field in banque.changed_data
|
||||||
|
)
|
||||||
|
)
|
||||||
messages.success(request, "Banque modifiée")
|
messages.success(request, "Banque modifiée")
|
||||||
return redirect("/cotisations/index_banque/")
|
return redirect("/cotisations/index_banque/")
|
||||||
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def del_banque(request):
|
def del_banque(request):
|
||||||
|
"""Supprime une banque"""
|
||||||
banque = DelBanqueForm(request.POST or None)
|
banque = DelBanqueForm(request.POST or None)
|
||||||
if banque.is_valid():
|
if banque.is_valid():
|
||||||
banque_dels = banque.cleaned_data['banques']
|
banque_dels = banque.cleaned_data['banques']
|
||||||
|
@ -360,17 +518,25 @@ def del_banque(request):
|
||||||
reversion.set_comment("Destruction")
|
reversion.set_comment("Destruction")
|
||||||
messages.success(request, "La banque a été supprimée")
|
messages.success(request, "La banque a été supprimée")
|
||||||
except ProtectedError:
|
except ProtectedError:
|
||||||
messages.error(request, "La banque %s est affectée à au moins une facture, vous ne pouvez pas la supprimer" % banque_del)
|
messages.error(request, "La banque %s est affectée à au moins\
|
||||||
|
une facture, vous ne pouvez pas la supprimer" % banque_del)
|
||||||
return redirect("/cotisations/index_banque/")
|
return redirect("/cotisations/index_banque/")
|
||||||
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
return form({'factureform': banque}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('tresorier')
|
@permission_required('tresorier')
|
||||||
def control(request):
|
def control(request):
|
||||||
|
"""Pour le trésorier, vue pour controler en masse les
|
||||||
|
factures.Case à cocher, pratique"""
|
||||||
options, created = GeneralOption.objects.get_or_create()
|
options, created = GeneralOption.objects.get_or_create()
|
||||||
pagination_number = options.pagination_number
|
pagination_number = options.pagination_number
|
||||||
facture_list = Facture.objects.order_by('date').reverse()
|
facture_list = Facture.objects.order_by('date').reverse()
|
||||||
controlform_set = modelformset_factory(Facture, fields=('control','valid'), extra=0)
|
controlform_set = modelformset_factory(
|
||||||
|
Facture,
|
||||||
|
fields=('control', 'valid'),
|
||||||
|
extra=0
|
||||||
|
)
|
||||||
paginator = Paginator(facture_list, pagination_number)
|
paginator = Paginator(facture_list, pagination_number)
|
||||||
page = request.GET.get('page')
|
page = request.GET.get('page')
|
||||||
try:
|
try:
|
||||||
|
@ -379,7 +545,9 @@ def control(request):
|
||||||
facture_list = paginator.page(1)
|
facture_list = paginator.page(1)
|
||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
facture_list = paginator.page(paginator.num.pages)
|
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])
|
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)
|
controlform = controlform_set(request.POST or None, queryset=page_query)
|
||||||
if controlform.is_valid():
|
if controlform.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
|
@ -387,32 +555,50 @@ def control(request):
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Controle trésorier")
|
reversion.set_comment("Controle trésorier")
|
||||||
return redirect("/cotisations/control/")
|
return redirect("/cotisations/control/")
|
||||||
return render(request, 'cotisations/control.html', {'facture_list': facture_list, 'controlform': controlform})
|
return render(request, 'cotisations/control.html', {
|
||||||
|
'facture_list': facture_list,
|
||||||
|
'controlform': controlform
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_article(request):
|
def index_article(request):
|
||||||
|
"""Affiche l'ensemble des articles en vente"""
|
||||||
article_list = Article.objects.order_by('name')
|
article_list = Article.objects.order_by('name')
|
||||||
return render(request, 'cotisations/index_article.html', {'article_list':article_list})
|
return render(request, 'cotisations/index_article.html', {
|
||||||
|
'article_list': article_list
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_paiement(request):
|
def index_paiement(request):
|
||||||
|
"""Affiche l'ensemble des moyens de paiement en vente"""
|
||||||
paiement_list = Paiement.objects.order_by('moyen')
|
paiement_list = Paiement.objects.order_by('moyen')
|
||||||
return render(request, 'cotisations/index_paiement.html', {'paiement_list':paiement_list})
|
return render(request, 'cotisations/index_paiement.html', {
|
||||||
|
'paiement_list': paiement_list
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index_banque(request):
|
def index_banque(request):
|
||||||
|
"""Affiche l'ensemble des banques"""
|
||||||
banque_list = Banque.objects.order_by('name')
|
banque_list = Banque.objects.order_by('name')
|
||||||
return render(request, 'cotisations/index_banque.html', {'banque_list':banque_list})
|
return render(request, 'cotisations/index_banque.html', {
|
||||||
|
'banque_list': banque_list
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
|
"""Affiche l'ensemble des factures, pour les cableurs et +"""
|
||||||
options, created = GeneralOption.objects.get_or_create()
|
options, created = GeneralOption.objects.get_or_create()
|
||||||
pagination_number = options.pagination_number
|
pagination_number = options.pagination_number
|
||||||
facture_list = Facture.objects.order_by('date').select_related('user').select_related('paiement').prefetch_related('vente_set').reverse()
|
facture_list = Facture.objects.order_by('date').select_related('user')\
|
||||||
|
.select_related('paiement').prefetch_related('vente_set').reverse()
|
||||||
paginator = Paginator(facture_list, pagination_number)
|
paginator = Paginator(facture_list, pagination_number)
|
||||||
page = request.GET.get('page')
|
page = request.GET.get('page')
|
||||||
try:
|
try:
|
||||||
|
@ -423,37 +609,43 @@ def index(request):
|
||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
# If page is out of range (e.g. 9999), deliver last page of results.
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
||||||
facture_list = paginator.page(paginator.num_pages)
|
facture_list = paginator.page(paginator.num_pages)
|
||||||
return render(request, 'cotisations/index.html', {'facture_list': facture_list})
|
return render(request, 'cotisations/index.html', {
|
||||||
|
'facture_list': facture_list
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def history(request, object, id):
|
def history(request, object, id):
|
||||||
|
"""Affiche l'historique de chaque objet"""
|
||||||
if object == 'facture':
|
if object == 'facture':
|
||||||
try:
|
try:
|
||||||
object_instance = Facture.objects.get(pk=id)
|
object_instance = Facture.objects.get(pk=id)
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
messages.error(request, "Facture inexistante")
|
messages.error(request, "Facture inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
if not request.user.has_perms(('cableur',)) and object_instance.user != request.user:
|
if not request.user.has_perms(('cableur',))\
|
||||||
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit cableur")
|
and object_instance.user != request.user:
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
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',)):
|
elif object == 'paiement' and request.user.has_perms(('cableur',)):
|
||||||
try:
|
try:
|
||||||
object_instance = Paiement.objects.get(pk=id)
|
object_instance = Paiement.objects.get(pk=id)
|
||||||
except Paiement.DoesNotExist:
|
except Paiement.DoesNotExist:
|
||||||
messages.error(request, "Paiement inexistant")
|
messages.error(request, "Paiement inexistant")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
elif object == 'article' and request.user.has_perms(('cableur',)):
|
elif object == 'article' and request.user.has_perms(('cableur',)):
|
||||||
try:
|
try:
|
||||||
object_instance = Article.objects.get(pk=id)
|
object_instance = Article.objects.get(pk=id)
|
||||||
except Article.DoesNotExist:
|
except Article.DoesNotExist:
|
||||||
messages.error(request, "Article inexistante")
|
messages.error(request, "Article inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
elif object == 'banque' and request.user.has_perms(('cableur',)):
|
elif object == 'banque' and request.user.has_perms(('cableur',)):
|
||||||
try:
|
try:
|
||||||
object_instance = Banque.objects.get(pk=id)
|
object_instance = Banque.objects.get(pk=id)
|
||||||
except Banque.DoesNotExist:
|
except Banque.DoesNotExist:
|
||||||
messages.error(request, "Banque inexistante")
|
messages.error(request, "Banque inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
else:
|
else:
|
||||||
messages.error(request, "Objet inconnu")
|
messages.error(request, "Objet inconnu")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
|
@ -470,4 +662,7 @@ def history(request, object, id):
|
||||||
except EmptyPage:
|
except EmptyPage:
|
||||||
# If page is out of range (e.g. 9999), deliver last page of results.
|
# If page is out of range (e.g. 9999), deliver last page of results.
|
||||||
reversions = paginator.page(paginator.num_pages)
|
reversions = paginator.page(paginator.num_pages)
|
||||||
return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance})
|
return render(request, 're2o/history.html', {
|
||||||
|
'reversions': reversions,
|
||||||
|
'object': object_instance
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue