From bbe687c29bfbebfe9f42c2f4b78c91837d8aa1ec Mon Sep 17 00:00:00 2001 From: David Sinquin Date: Tue, 18 Jul 2017 23:57:57 +0200 Subject: [PATCH] Rework facture management to avoid hardcoded check database id in JS. --- cotisations/forms.py | 5 +++-- cotisations/models.py | 5 +++++ .../templates/cotisations/new_facture.html | 18 +++++++----------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cotisations/forms.py b/cotisations/forms.py index b12bc53e..e323bf63 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -46,7 +46,7 @@ class NewFactureForm(ModelForm): banque = cleaned_data.get("banque") if not paiement: raise forms.ValidationError("Le moyen de paiement est obligatoire.") - elif paiement.moyen.lower()=="chèque" or paiement.moyen.lower()=="cheque" and not (cheque and banque): + elif paiement.type_ == "check" and not (cheque and banque): raise forms.ValidationError("Le numéro de chèque et la banque sont obligatoires.") return cleaned_data @@ -112,11 +112,12 @@ class DelArticleForm(ModelForm): class PaiementForm(ModelForm): class Meta: model = Paiement - fields = ['moyen'] + fields = ['moyen', 'type_'] def __init__(self, *args, **kwargs): super(PaiementForm, self).__init__(*args, **kwargs) self.fields['moyen'].label = 'Moyen de paiement à ajouter' + self.fields['type_'].label = 'Type de paiement à ajouter' class DelPaiementForm(ModelForm): paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple) diff --git a/cotisations/models.py b/cotisations/models.py index 24eb2b5a..e6efcd80 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -130,8 +130,13 @@ class Banque(models.Model): class Paiement(models.Model): PRETTY_NAME = "Moyens de paiement" + PAYMENT_TYPES = ( + ('check', 'Chèque'), + (None, 'Autre'), + ) moyen = models.CharField(max_length=255) + type_ = models.ChoiceField(choices=PAYMENT_TYPES) def __str__(self): return self.moyen diff --git a/cotisations/templates/cotisations/new_facture.html b/cotisations/templates/cotisations/new_facture.html index 9c0aefe9..416ba14f 100644 --- a/cotisations/templates/cotisations/new_facture.html +++ b/cotisations/templates/cotisations/new_facture.html @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

Nouvelle facture

{% bootstrap_form factureform %} {{ venteform.management_form }} +

Articles de la facture

{% for form in venteform.forms %} @@ -57,10 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,