forms.py 5.55 KB
Newer Older
lhark's avatar
lhark committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 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.

23
from django import forms
Dalahro's avatar
Dalahro committed
24
from django.forms import ModelForm, Form
Dalahro's avatar
Dalahro committed
25
from django import forms
26
from django.core.validators import MinValueValidator
Dalahro's avatar
Dalahro committed
27
from .models import Article, Paiement, Facture, Banque, Vente
28 29 30 31 32 33 34 35 36

class NewFactureForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super(NewFactureForm, self).__init__(*args, **kwargs)
        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é"
        self.fields['paiement'].empty_label = "Séléctionner un moyen de paiement"
Gabriel Detraz's avatar
Gabriel Detraz committed
37
        self.fields['paiement'].widget.attrs['data-cheque'] = Paiement.objects.filter(type_paiement=1).first().id
38 39 40

    class Meta:
        model = Facture
Dalahro's avatar
Dalahro committed
41
        fields = ['paiement','banque','cheque']
42 43 44 45 46 47

    def clean(self):
        cleaned_data=super(NewFactureForm, self).clean()
        paiement = cleaned_data.get("paiement")
        cheque = cleaned_data.get("cheque")
        banque = cleaned_data.get("banque")
48
        if not paiement:
David Sinquin's avatar
David Sinquin committed
49
            raise forms.ValidationError("Le moyen de paiement est obligatoire.")
Gabriel Detraz's avatar
Gabriel Detraz committed
50
        elif paiement.type_paiement == "check" and not (cheque and banque):
David Sinquin's avatar
David Sinquin committed
51
            raise forms.ValidationError("Le numéro de chèque et la banque sont obligatoires.")
52 53
        return cleaned_data

chibrac's avatar
chibrac committed
54 55 56 57 58 59 60 61 62 63 64 65
class CreditSoldeForm(NewFactureForm):
    class Meta(NewFactureForm.Meta):
        model = Facture
        fields = ['paiement','banque','cheque']

    def __init__(self, *args, **kwargs):
        super(CreditSoldeForm, self).__init__(*args, **kwargs)
        self.fields['paiement'].queryset = Paiement.objects.exclude(moyen='solde').exclude(moyen="Solde")


    montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)

Dalahro's avatar
Dalahro committed
66
class SelectArticleForm(Form):
67
    article = forms.ModelChoiceField(queryset=Article.objects.all(), label="Article", required=True)
68
    quantity = forms.IntegerField(label="Quantité", validators=[MinValueValidator(1)], required=True)
Dalahro's avatar
Dalahro committed
69

Dalahro's avatar
Dalahro committed
70 71
class NewFactureFormPdf(Form):
    article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article")
72
    number = forms.IntegerField(label="Quantité", validators=[MinValueValidator(1)])
Dalahro's avatar
Dalahro committed
73 74
    paid = forms.BooleanField(label="Payé", required=False)
    dest = forms.CharField(required=True, max_length=255, label="Destinataire")
Dalahro's avatar
Dalahro committed
75 76
    chambre = forms.CharField(required=False, max_length=10, label="Adresse")
    fid = forms.CharField(required=True, max_length=10, label="Numéro de la facture")
Dalahro's avatar
Dalahro committed
77

78 79
class EditFactureForm(NewFactureForm):
    class Meta(NewFactureForm.Meta):
80
        fields = ['paiement','banque','cheque','user']
81 82 83 84 85

    def __init__(self, *args, **kwargs):
        super(EditFactureForm, self).__init__(*args, **kwargs)
        self.fields['user'].label = 'Adherent'
        self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
86 87 88 89 90 91 92

class TrezEditFactureForm(EditFactureForm):
    class Meta(EditFactureForm.Meta):
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(TrezEditFactureForm, self).__init__(*args, **kwargs)
93
        self.fields['valid'].label = 'Validité de la facture'
David Sinquin's avatar
David Sinquin committed
94
        self.fields['control'].label = 'Contrôle de la facture'
95

96 97 98 99 100 101 102 103 104 105

class ArticleForm(ModelForm):
    class Meta:
        model = Article
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(ArticleForm, self).__init__(*args, **kwargs)
        self.fields['name'].label = "Désignation de l'article"

106
class DelArticleForm(Form):
107 108 109 110 111
    articles = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Articles actuels",  widget=forms.CheckboxSelectMultiple)

class PaiementForm(ModelForm):
    class Meta:
        model = Paiement
Gabriel Detraz's avatar
Gabriel Detraz committed
112
        fields = ['moyen', 'type_paiement']
113 114 115 116

    def __init__(self, *args, **kwargs):
        super(PaiementForm, self).__init__(*args, **kwargs)
        self.fields['moyen'].label = 'Moyen de paiement à ajouter'
Gabriel Detraz's avatar
Gabriel Detraz committed
117
        self.fields['type_paiement'].label = 'Type de paiement à ajouter'
118

119
class DelPaiementForm(Form):
120 121
    paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels",  widget=forms.CheckboxSelectMultiple)

chirac's avatar
chirac committed
122 123 124 125 126 127 128 129 130
class BanqueForm(ModelForm):
    class Meta:
        model = Banque
        fields = ['name']

    def __init__(self, *args, **kwargs):
        super(BanqueForm, self).__init__(*args, **kwargs)
        self.fields['name'].label = 'Banque à ajouter'

131
class DelBanqueForm(Form):
chirac's avatar
chirac committed
132
    banques = forms.ModelMultipleChoiceField(queryset=Banque.objects.all(), label="Banques actuelles",  widget=forms.CheckboxSelectMultiple)