mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 14:42:25 +00:00
Pep8 et doc strings
This commit is contained in:
parent
68b1dea482
commit
467e34acaa
1 changed files with 81 additions and 19 deletions
|
@ -28,7 +28,10 @@ from django import forms
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from .models import Article, Paiement, Facture, Banque, Vente
|
from .models import Article, Paiement, Facture, Banque, Vente
|
||||||
|
|
||||||
|
|
||||||
class NewFactureForm(ModelForm):
|
class NewFactureForm(ModelForm):
|
||||||
|
"""Creation d'une facture, moyen de paiement, banque et numero
|
||||||
|
de cheque"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
@ -36,58 +39,91 @@ class NewFactureForm(ModelForm):
|
||||||
self.fields['banque'].required = False
|
self.fields['banque'].required = False
|
||||||
self.fields['cheque'].label = 'Numero de chèque'
|
self.fields['cheque'].label = 'Numero de chèque'
|
||||||
self.fields['banque'].empty_label = "Non renseigné"
|
self.fields['banque'].empty_label = "Non renseigné"
|
||||||
self.fields['paiement'].empty_label = "Séléctionner un moyen de paiement"
|
self.fields['paiement'].empty_label = "Séléctionner\
|
||||||
self.fields['paiement'].widget.attrs['data-cheque'] = Paiement.objects.filter(type_paiement=1).first().id
|
un moyen de paiement"
|
||||||
|
self.fields['paiement'].widget.attrs['data-cheque'] = Paiement.objects\
|
||||||
|
.filter(type_paiement=1).first().id
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Facture
|
model = Facture
|
||||||
fields = ['paiement','banque','cheque']
|
fields = ['paiement', 'banque', 'cheque']
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data=super(NewFactureForm, self).clean()
|
cleaned_data = super(NewFactureForm, self).clean()
|
||||||
paiement = cleaned_data.get("paiement")
|
paiement = cleaned_data.get("paiement")
|
||||||
cheque = cleaned_data.get("cheque")
|
cheque = cleaned_data.get("cheque")
|
||||||
banque = cleaned_data.get("banque")
|
banque = cleaned_data.get("banque")
|
||||||
if not paiement:
|
if not paiement:
|
||||||
raise forms.ValidationError("Le moyen de paiement est obligatoire.")
|
raise forms.ValidationError("Le moyen de paiement est obligatoire")
|
||||||
elif paiement.type_paiement == "check" and not (cheque and banque):
|
elif paiement.type_paiement == "check" and not (cheque and banque):
|
||||||
raise forms.ValidationError("Le numéro de chèque et la banque sont obligatoires.")
|
raise forms.ValidationError("Le numéro de chèque et\
|
||||||
|
la banque sont obligatoires.")
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
|
|
||||||
class CreditSoldeForm(NewFactureForm):
|
class CreditSoldeForm(NewFactureForm):
|
||||||
|
"""Permet de faire des opérations sur le solde si il est activé"""
|
||||||
class Meta(NewFactureForm.Meta):
|
class Meta(NewFactureForm.Meta):
|
||||||
model = Facture
|
model = Facture
|
||||||
fields = ['paiement','banque','cheque']
|
fields = ['paiement', 'banque', 'cheque']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(CreditSoldeForm, self).__init__(*args, **kwargs)
|
super(CreditSoldeForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['paiement'].queryset = Paiement.objects.exclude(moyen='solde').exclude(moyen="Solde")
|
self.fields['paiement'].queryset = Paiement.objects.exclude(
|
||||||
|
moyen='solde'
|
||||||
|
).exclude(moyen="Solde")
|
||||||
|
|
||||||
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
||||||
|
|
||||||
|
|
||||||
class SelectArticleForm(Form):
|
class SelectArticleForm(Form):
|
||||||
article = forms.ModelChoiceField(queryset=Article.objects.all(), label="Article", required=True)
|
"""Selection d'un article lors de la creation d'une facture"""
|
||||||
quantity = forms.IntegerField(label="Quantité", validators=[MinValueValidator(1)], required=True)
|
article = forms.ModelChoiceField(
|
||||||
|
queryset=Article.objects.all(),
|
||||||
|
label="Article",
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
quantity = forms.IntegerField(
|
||||||
|
label="Quantité",
|
||||||
|
validators=[MinValueValidator(1)],
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NewFactureFormPdf(Form):
|
class NewFactureFormPdf(Form):
|
||||||
article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article")
|
"""Creation d'un pdf facture par le trésorier"""
|
||||||
number = forms.IntegerField(label="Quantité", validators=[MinValueValidator(1)])
|
article = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Article.objects.all(),
|
||||||
|
label="Article"
|
||||||
|
)
|
||||||
|
number = forms.IntegerField(
|
||||||
|
label="Quantité",
|
||||||
|
validators=[MinValueValidator(1)]
|
||||||
|
)
|
||||||
paid = forms.BooleanField(label="Payé", required=False)
|
paid = forms.BooleanField(label="Payé", required=False)
|
||||||
dest = forms.CharField(required=True, max_length=255, label="Destinataire")
|
dest = forms.CharField(required=True, max_length=255, label="Destinataire")
|
||||||
chambre = forms.CharField(required=False, max_length=10, label="Adresse")
|
chambre = forms.CharField(required=False, max_length=10, label="Adresse")
|
||||||
fid = forms.CharField(required=True, max_length=10, label="Numéro de la facture")
|
fid = forms.CharField(
|
||||||
|
required=True,
|
||||||
|
max_length=10,
|
||||||
|
label="Numéro de la facture"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EditFactureForm(NewFactureForm):
|
class EditFactureForm(NewFactureForm):
|
||||||
|
"""Edition d'une facture : moyen de paiement, banque, user parent"""
|
||||||
class Meta(NewFactureForm.Meta):
|
class Meta(NewFactureForm.Meta):
|
||||||
fields = ['paiement','banque','cheque','user']
|
fields = ['paiement', 'banque', 'cheque', 'user']
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(EditFactureForm, self).__init__(*args, **kwargs)
|
super(EditFactureForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['user'].label = 'Adherent'
|
self.fields['user'].label = 'Adherent'
|
||||||
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
|
self.fields['user'].empty_label = "Séléctionner\
|
||||||
|
l'adhérent propriétaire"
|
||||||
|
|
||||||
|
|
||||||
class TrezEditFactureForm(EditFactureForm):
|
class TrezEditFactureForm(EditFactureForm):
|
||||||
|
"""Vue pour édition controle trésorier"""
|
||||||
class Meta(EditFactureForm.Meta):
|
class Meta(EditFactureForm.Meta):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
@ -98,6 +134,7 @@ class TrezEditFactureForm(EditFactureForm):
|
||||||
|
|
||||||
|
|
||||||
class ArticleForm(ModelForm):
|
class ArticleForm(ModelForm):
|
||||||
|
"""Creation d'un article. Champs : nom, cotisation, durée"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Article
|
model = Article
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -107,10 +144,20 @@ class ArticleForm(ModelForm):
|
||||||
super(ArticleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(ArticleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['name'].label = "Désignation de l'article"
|
self.fields['name'].label = "Désignation de l'article"
|
||||||
|
|
||||||
|
|
||||||
class DelArticleForm(Form):
|
class DelArticleForm(Form):
|
||||||
articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels", widget=forms.CheckboxSelectMultiple)
|
"""Suppression d'un ou plusieurs articles en vente. Choix
|
||||||
|
parmis les modèles"""
|
||||||
|
articles = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Article.objects.all(),
|
||||||
|
label="Articles actuels",
|
||||||
|
widget=forms.CheckboxSelectMultiple
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PaiementForm(ModelForm):
|
class PaiementForm(ModelForm):
|
||||||
|
"""Creation d'un moyen de paiement, champ text moyen et type
|
||||||
|
permettant d'indiquer si il s'agit d'un chèque ou non pour le form"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Paiement
|
model = Paiement
|
||||||
fields = ['moyen', 'type_paiement']
|
fields = ['moyen', 'type_paiement']
|
||||||
|
@ -121,10 +168,19 @@ class PaiementForm(ModelForm):
|
||||||
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
|
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
|
||||||
self.fields['type_paiement'].label = 'Type de paiement à ajouter'
|
self.fields['type_paiement'].label = 'Type de paiement à ajouter'
|
||||||
|
|
||||||
|
|
||||||
class DelPaiementForm(Form):
|
class DelPaiementForm(Form):
|
||||||
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)
|
"""Suppression d'un ou plusieurs moyens de paiements, selection
|
||||||
|
parmis les models"""
|
||||||
|
paiements = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Paiement.objects.all(),
|
||||||
|
label="Moyens de paiement actuels",
|
||||||
|
widget=forms.CheckboxSelectMultiple
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BanqueForm(ModelForm):
|
class BanqueForm(ModelForm):
|
||||||
|
"""Creation d'une banque, field name"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Banque
|
model = Banque
|
||||||
fields = ['name']
|
fields = ['name']
|
||||||
|
@ -134,5 +190,11 @@ class BanqueForm(ModelForm):
|
||||||
super(BanqueForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(BanqueForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['name'].label = 'Banque à ajouter'
|
self.fields['name'].label = 'Banque à ajouter'
|
||||||
|
|
||||||
|
|
||||||
class DelBanqueForm(Form):
|
class DelBanqueForm(Form):
|
||||||
banques = forms.ModelMultipleChoiceField(queryset=Banque.objects.all(), label="Banques actuelles", widget=forms.CheckboxSelectMultiple)
|
"""Selection d'une ou plusieurs banques, pour suppression"""
|
||||||
|
banques = forms.ModelMultipleChoiceField(
|
||||||
|
queryset=Banque.objects.all(),
|
||||||
|
label="Banques actuelles",
|
||||||
|
widget=forms.CheckboxSelectMultiple
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue