2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
|
|
|
# Copyright © 2017 Goulven Kermarec
|
|
|
|
# Copyright © 2017 Augustin Lemesle
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2017-10-13 21:15:07 +00:00
|
|
|
"""
|
|
|
|
Forms de l'application cotisation de re2o. Dépendance avec les models,
|
|
|
|
importé par les views.
|
2017-01-15 23:01:18 +00:00
|
|
|
|
2017-10-13 21:15:07 +00:00
|
|
|
Permet de créer une nouvelle facture pour un user (NewFactureForm),
|
|
|
|
et de l'editer (soit l'user avec EditFactureForm,
|
|
|
|
soit le trésorier avec TrezEdit qui a plus de possibilités que self
|
|
|
|
notamment sur le controle trésorier)
|
|
|
|
|
|
|
|
SelectArticleForm est utilisée lors de la creation d'une facture en
|
|
|
|
parrallèle de NewFacture pour le choix des articles désirés.
|
|
|
|
(la vue correspondante est unique)
|
|
|
|
|
|
|
|
ArticleForm, BanqueForm, PaiementForm permettent aux admin d'ajouter,
|
|
|
|
éditer ou supprimer une banque/moyen de paiement ou un article
|
|
|
|
"""
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
from django import forms
|
2017-10-28 04:02:53 +00:00
|
|
|
from django.db.models import Q
|
2016-07-09 21:26:17 +00:00
|
|
|
from django.forms import ModelForm, Form
|
2016-07-14 18:51:45 +00:00
|
|
|
from django.core.validators import MinValueValidator
|
2017-10-13 21:15:07 +00:00
|
|
|
from .models import Article, Paiement, Facture, Banque
|
2016-07-06 19:23:05 +00:00
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
class NewFactureForm(ModelForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Creation d'une facture, moyen de paiement, banque et numero
|
|
|
|
de cheque"""
|
2016-07-06 19:23:05 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 19:23:05 +00:00
|
|
|
self.fields['cheque'].required = False
|
|
|
|
self.fields['banque'].required = False
|
|
|
|
self.fields['cheque'].label = 'Numero de chèque'
|
|
|
|
self.fields['banque'].empty_label = "Non renseigné"
|
2017-10-13 03:24:57 +00:00
|
|
|
self.fields['paiement'].empty_label = "Séléctionner\
|
|
|
|
un moyen de paiement"
|
|
|
|
self.fields['paiement'].widget.attrs['data-cheque'] = Paiement.objects\
|
|
|
|
.filter(type_paiement=1).first().id
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Facture
|
2017-10-13 03:24:57 +00:00
|
|
|
fields = ['paiement', 'banque', 'cheque']
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
def clean(self):
|
2017-10-13 03:24:57 +00:00
|
|
|
cleaned_data = super(NewFactureForm, self).clean()
|
2016-07-06 19:23:05 +00:00
|
|
|
paiement = cleaned_data.get("paiement")
|
|
|
|
cheque = cleaned_data.get("cheque")
|
|
|
|
banque = cleaned_data.get("banque")
|
2016-07-14 11:55:46 +00:00
|
|
|
if not paiement:
|
2017-10-13 03:24:57 +00:00
|
|
|
raise forms.ValidationError("Le moyen de paiement est obligatoire")
|
2017-07-22 15:57:58 +00:00
|
|
|
elif paiement.type_paiement == "check" and not (cheque and banque):
|
2017-10-13 03:24:57 +00:00
|
|
|
raise forms.ValidationError("Le numéro de chèque et\
|
|
|
|
la banque sont obligatoires.")
|
2016-07-06 19:23:05 +00:00
|
|
|
return cleaned_data
|
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2017-06-26 17:23:01 +00:00
|
|
|
class CreditSoldeForm(NewFactureForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Permet de faire des opérations sur le solde si il est activé"""
|
2017-06-26 17:23:01 +00:00
|
|
|
class Meta(NewFactureForm.Meta):
|
|
|
|
model = Facture
|
2017-10-13 03:24:57 +00:00
|
|
|
fields = ['paiement', 'banque', 'cheque']
|
2017-06-26 17:23:01 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(CreditSoldeForm, self).__init__(*args, **kwargs)
|
2017-10-13 03:24:57 +00:00
|
|
|
self.fields['paiement'].queryset = Paiement.objects.exclude(
|
|
|
|
moyen='solde'
|
|
|
|
).exclude(moyen="Solde")
|
2017-06-26 17:23:01 +00:00
|
|
|
|
|
|
|
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2017-10-28 04:02:53 +00:00
|
|
|
class SelectUserArticleForm(Form):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Selection d'un article lors de la creation d'une facture"""
|
|
|
|
article = forms.ModelChoiceField(
|
2017-10-28 04:02:53 +00:00
|
|
|
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Adherent')),
|
|
|
|
label="Article",
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
quantity = forms.IntegerField(
|
|
|
|
label="Quantité",
|
|
|
|
validators=[MinValueValidator(1)],
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SelectClubArticleForm(Form):
|
|
|
|
"""Selection d'un article lors de la creation d'une facture"""
|
|
|
|
article = forms.ModelChoiceField(
|
|
|
|
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Club')),
|
2017-10-13 03:24:57 +00:00
|
|
|
label="Article",
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
quantity = forms.IntegerField(
|
|
|
|
label="Quantité",
|
|
|
|
validators=[MinValueValidator(1)],
|
|
|
|
required=True
|
|
|
|
)
|
|
|
|
|
2016-07-13 23:54:06 +00:00
|
|
|
|
2016-07-09 21:26:17 +00:00
|
|
|
class NewFactureFormPdf(Form):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Creation d'un pdf facture par le trésorier"""
|
|
|
|
article = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Article.objects.all(),
|
|
|
|
label="Article"
|
|
|
|
)
|
|
|
|
number = forms.IntegerField(
|
|
|
|
label="Quantité",
|
|
|
|
validators=[MinValueValidator(1)]
|
|
|
|
)
|
2016-07-09 21:26:17 +00:00
|
|
|
paid = forms.BooleanField(label="Payé", required=False)
|
|
|
|
dest = forms.CharField(required=True, max_length=255, label="Destinataire")
|
2016-07-13 23:54:06 +00:00
|
|
|
chambre = forms.CharField(required=False, max_length=10, label="Adresse")
|
2017-10-13 03:24:57 +00:00
|
|
|
fid = forms.CharField(
|
|
|
|
required=True,
|
|
|
|
max_length=10,
|
|
|
|
label="Numéro de la facture"
|
|
|
|
)
|
|
|
|
|
2016-07-09 21:26:17 +00:00
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
class EditFactureForm(NewFactureForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Edition d'une facture : moyen de paiement, banque, user parent"""
|
2016-07-06 19:23:05 +00:00
|
|
|
class Meta(NewFactureForm.Meta):
|
2017-10-13 03:24:57 +00:00
|
|
|
fields = ['paiement', 'banque', 'cheque', 'user']
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(EditFactureForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['user'].label = 'Adherent'
|
2017-10-13 03:24:57 +00:00
|
|
|
self.fields['user'].empty_label = "Séléctionner\
|
|
|
|
l'adhérent propriétaire"
|
|
|
|
|
2016-07-14 20:29:30 +00:00
|
|
|
|
|
|
|
class TrezEditFactureForm(EditFactureForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Vue pour édition controle trésorier"""
|
2016-07-14 20:29:30 +00:00
|
|
|
class Meta(EditFactureForm.Meta):
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(TrezEditFactureForm, self).__init__(*args, **kwargs)
|
2016-07-14 18:51:45 +00:00
|
|
|
self.fields['valid'].label = 'Validité de la facture'
|
2017-07-18 21:57:57 +00:00
|
|
|
self.fields['control'].label = 'Contrôle de la facture'
|
2016-07-14 20:29:30 +00:00
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
class ArticleForm(ModelForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Creation d'un article. Champs : nom, cotisation, durée"""
|
2016-07-06 19:23:05 +00:00
|
|
|
class Meta:
|
|
|
|
model = Article
|
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(ArticleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 19:23:05 +00:00
|
|
|
self.fields['name'].label = "Désignation de l'article"
|
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2017-08-18 22:01:06 +00:00
|
|
|
class DelArticleForm(Form):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""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
|
|
|
|
)
|
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
class PaiementForm(ModelForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""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"""
|
2016-07-06 19:23:05 +00:00
|
|
|
class Meta:
|
|
|
|
model = Paiement
|
2017-07-22 15:57:58 +00:00
|
|
|
fields = ['moyen', 'type_paiement']
|
2016-07-06 19:23:05 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(PaiementForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 19:23:05 +00:00
|
|
|
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
|
2017-07-22 15:57:58 +00:00
|
|
|
self.fields['type_paiement'].label = 'Type de paiement à ajouter'
|
2016-07-06 19:23:05 +00:00
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2017-08-18 22:01:06 +00:00
|
|
|
class DelPaiementForm(Form):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""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
|
|
|
|
)
|
|
|
|
|
2016-07-06 19:23:05 +00:00
|
|
|
|
2016-07-06 20:20:49 +00:00
|
|
|
class BanqueForm(ModelForm):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Creation d'une banque, field name"""
|
2016-07-06 20:20:49 +00:00
|
|
|
class Meta:
|
|
|
|
model = Banque
|
|
|
|
fields = ['name']
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-08 23:34:49 +00:00
|
|
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
2017-10-08 20:22:04 +00:00
|
|
|
super(BanqueForm, self).__init__(*args, prefix=prefix, **kwargs)
|
2016-07-06 20:20:49 +00:00
|
|
|
self.fields['name'].label = 'Banque à ajouter'
|
|
|
|
|
2017-10-13 03:24:57 +00:00
|
|
|
|
2017-08-18 22:01:06 +00:00
|
|
|
class DelBanqueForm(Form):
|
2017-10-13 03:24:57 +00:00
|
|
|
"""Selection d'une ou plusieurs banques, pour suppression"""
|
|
|
|
banques = forms.ModelMultipleChoiceField(
|
|
|
|
queryset=Banque.objects.all(),
|
|
|
|
label="Banques actuelles",
|
|
|
|
widget=forms.CheckboxSelectMultiple
|
|
|
|
)
|