mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 06:32:26 +00:00
Passage d'un coup de pylint
This commit is contained in:
parent
9ab06207bd
commit
0f47ab79eb
3 changed files with 79 additions and 84 deletions
|
@ -28,23 +28,30 @@ from reversion.admin import VersionAdmin
|
||||||
|
|
||||||
from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
|
from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
|
||||||
|
|
||||||
|
|
||||||
class FactureAdmin(VersionAdmin):
|
class FactureAdmin(VersionAdmin):
|
||||||
list_display = ('user','paiement','date','valid','control')
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VenteAdmin(VersionAdmin):
|
class VenteAdmin(VersionAdmin):
|
||||||
list_display = ('facture','name','prix','number','iscotisation','duration')
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ArticleAdmin(VersionAdmin):
|
class ArticleAdmin(VersionAdmin):
|
||||||
list_display = ('name','prix','iscotisation','duration')
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BanqueAdmin(VersionAdmin):
|
class BanqueAdmin(VersionAdmin):
|
||||||
list_display = ('name',)
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PaiementAdmin(VersionAdmin):
|
class PaiementAdmin(VersionAdmin):
|
||||||
list_display = ('moyen','type_paiement')
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CotisationAdmin(VersionAdmin):
|
class CotisationAdmin(VersionAdmin):
|
||||||
list_display = ('vente','date_start','date_end')
|
pass
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Facture, FactureAdmin)
|
admin.site.register(Facture, FactureAdmin)
|
||||||
admin.site.register(Article, ArticleAdmin)
|
admin.site.register(Article, ArticleAdmin)
|
||||||
|
|
|
@ -24,40 +24,29 @@
|
||||||
# Goulven Kermarec, Gabriel Détraz
|
# Goulven Kermarec, Gabriel Détraz
|
||||||
# Gplv2
|
# Gplv2
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import os
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.template.context_processors import csrf
|
|
||||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||||
from django.template import Context, RequestContext, loader
|
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db.models import Max, ProtectedError
|
from django.db.models import ProtectedError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.forms import modelformset_factory, formset_factory
|
from django.forms import modelformset_factory, formset_factory
|
||||||
import os
|
from django.utils import timezone
|
||||||
from reversion import revisions as reversion
|
from reversion import revisions as reversion
|
||||||
from reversion.models import Version
|
from reversion.models import Version
|
||||||
|
# Import des models, forms et fonctions re2o
|
||||||
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
|
from users.models import User
|
||||||
|
from re2o.settings import LOGO_PATH
|
||||||
|
from re2o import settings
|
||||||
|
from re2o.views import form
|
||||||
|
from preferences.models import OptionalUser, AssoOption, GeneralOption
|
||||||
|
from .models import Facture, Article, Vente, Paiement, Banque
|
||||||
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
|
from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm
|
||||||
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm
|
from .forms import ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm
|
||||||
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf
|
from .forms import BanqueForm, DelBanqueForm, NewFactureFormPdf
|
||||||
from .forms import SelectArticleForm, CreditSoldeForm
|
from .forms import SelectArticleForm, CreditSoldeForm
|
||||||
from users.models import User
|
|
||||||
from .tex import render_tex
|
from .tex import render_tex
|
||||||
from re2o.settings import LOGO_PATH
|
|
||||||
from re2o import settings
|
|
||||||
from preferences.models import OptionalUser, AssoOption, GeneralOption
|
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
|
|
||||||
def form(ctx, template, request):
|
|
||||||
c = ctx
|
|
||||||
c.update(csrf(request))
|
|
||||||
return render(request, template, c)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -82,17 +71,17 @@ def new_facture(request, userid):
|
||||||
facture_form = NewFactureForm(request.POST or None, instance=facture)
|
facture_form = NewFactureForm(request.POST or None, instance=facture)
|
||||||
article_formset = formset_factory(SelectArticleForm)(request.POST or None)
|
article_formset = formset_factory(SelectArticleForm)(request.POST or None)
|
||||||
if facture_form.is_valid() and article_formset.is_valid():
|
if facture_form.is_valid() and article_formset.is_valid():
|
||||||
new_facture = facture_form.save(commit=False)
|
new_facture_instance = facture_form.save(commit=False)
|
||||||
articles = article_formset
|
articles = article_formset
|
||||||
# Si au moins un article est rempli
|
# Si au moins un article est rempli
|
||||||
if any(art.cleaned_data for art in articles):
|
if any(art.cleaned_data for art in articles):
|
||||||
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,
|
# Si on paye par solde, que l'option est activée,
|
||||||
# on vérifie que le négatif n'est pas atteint
|
# 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(
|
if new_facture_instance.paiement == Paiement.objects.get_or_create(
|
||||||
moyen='solde'
|
moyen='solde'
|
||||||
)[0]:
|
)[0]:
|
||||||
prix_total = 0
|
prix_total = 0
|
||||||
|
@ -105,7 +94,7 @@ def new_facture(request, userid):
|
||||||
effectuer l'opération")
|
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_instance.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Création")
|
reversion.set_comment("Création")
|
||||||
for art_item in articles:
|
for art_item in articles:
|
||||||
|
@ -113,7 +102,7 @@ def new_facture(request, userid):
|
||||||
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(
|
new_vente = Vente.objects.create(
|
||||||
facture=new_facture,
|
facture=new_facture_instance,
|
||||||
name=article.name,
|
name=article.name,
|
||||||
prix=article.prix,
|
prix=article.prix,
|
||||||
iscotisation=article.iscotisation,
|
iscotisation=article.iscotisation,
|
||||||
|
@ -155,7 +144,7 @@ def new_facture_pdf(request):
|
||||||
Vente ou Facture correspondant en bdd"""
|
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()
|
||||||
tbl = []
|
tbl = []
|
||||||
article = facture_form.cleaned_data['article']
|
article = facture_form.cleaned_data['article']
|
||||||
quantite = facture_form.cleaned_data['number']
|
quantite = facture_form.cleaned_data['number']
|
||||||
|
@ -163,8 +152,8 @@ def new_facture_pdf(request):
|
||||||
destinataire = facture_form.cleaned_data['dest']
|
destinataire = facture_form.cleaned_data['dest']
|
||||||
chambre = facture_form.cleaned_data['chambre']
|
chambre = facture_form.cleaned_data['chambre']
|
||||||
fid = facture_form.cleaned_data['fid']
|
fid = facture_form.cleaned_data['fid']
|
||||||
for a in article:
|
for art in article:
|
||||||
tbl.append([a, quantite, a.prix * quantite])
|
tbl.append([art, quantite, art.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', {
|
return render_tex(request, 'cotisations/factures.tex', {
|
||||||
|
@ -207,11 +196,11 @@ def facture_pdf(request, factureid):
|
||||||
messages.error(request, "Vous ne pouvez pas afficher\
|
messages.error(request, "Vous ne pouvez pas afficher\
|
||||||
une facture non valide")
|
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)
|
ventes_objects = 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 vente in ventes_objects:
|
||||||
ventes.append([v, v.number, v.prix_total])
|
ventes.append([vente, vente.number, vente.prix_total])
|
||||||
return render_tex(request, 'cotisations/factures.tex', {
|
return render_tex(request, 'cotisations/factures.tex', {
|
||||||
'paid': True,
|
'paid': True,
|
||||||
'fid': facture.id,
|
'fid': facture.id,
|
||||||
|
@ -266,8 +255,7 @@ def edit_facture(request, factureid):
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
|
||||||
field for form in vente_form for field
|
field for form in vente_form for field
|
||||||
in facture_form.changed_data + form.changed_data)
|
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({
|
return form({
|
||||||
|
@ -286,7 +274,7 @@ def del_facture(request, 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\
|
messages.error(request, "Vous ne pouvez pas editer une facture\
|
||||||
controlée ou invalidée par le trésorier")
|
controlée ou invalidée par le trésorier")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
|
@ -529,7 +517,7 @@ def del_banque(request):
|
||||||
def control(request):
|
def control(request):
|
||||||
"""Pour le trésorier, vue pour controler en masse les
|
"""Pour le trésorier, vue pour controler en masse les
|
||||||
factures.Case à cocher, pratique"""
|
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(
|
controlform_set = modelformset_factory(
|
||||||
|
@ -595,7 +583,7 @@ def index_banque(request):
|
||||||
@permission_required('cableur')
|
@permission_required('cableur')
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Affiche l'ensemble des factures, pour les cableurs et +"""
|
"""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')\
|
facture_list = Facture.objects.order_by('date').select_related('user')\
|
||||||
.select_related('paiement').prefetch_related('vente_set').reverse()
|
.select_related('paiement').prefetch_related('vente_set').reverse()
|
||||||
|
@ -615,11 +603,11 @@ def index(request):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def history(request, object, id):
|
def history(request, object, object_id):
|
||||||
"""Affiche l'historique de chaque objet"""
|
"""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=object_id)
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
messages.error(request, "Facture inexistante")
|
messages.error(request, "Facture inexistante")
|
||||||
return redirect("/cotisations/")
|
return redirect("/cotisations/")
|
||||||
|
@ -630,26 +618,26 @@ def history(request, object, id):
|
||||||
return redirect("/users/profil/" + str(request.user.id))
|
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=object_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=object_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=object_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/")
|
||||||
options, created = GeneralOption.objects.get_or_create()
|
options, _created = GeneralOption.objects.get_or_create()
|
||||||
pagination_number = options.pagination_number
|
pagination_number = options.pagination_number
|
||||||
reversions = Version.objects.get_for_object(object_instance)
|
reversions = Version.objects.get_for_object(object_instance)
|
||||||
paginator = Paginator(reversions, pagination_number)
|
paginator = Paginator(reversions, pagination_number)
|
||||||
|
|
|
@ -29,9 +29,9 @@ from django.template import Context, RequestContext, loader
|
||||||
from preferences.models import Service
|
from preferences.models import Service
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
context = ctx
|
||||||
c.update(csrf(request))
|
context.update(csrf(request))
|
||||||
return render(request, template, c)
|
return render(request, template, context)
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
|
Loading…
Reference in a new issue