From 286fb6b0e2b88b49986c74c0c038520d7c27f983 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 4 Sep 2017 15:31:48 +0200 Subject: [PATCH] Fix js paiement --- cotisations/forms.py | 1 + cotisations/models.py | 5 +++++ cotisations/templates/cotisations/aff_article.html | 2 +- cotisations/templates/cotisations/new_facture.html | 6 +++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cotisations/forms.py b/cotisations/forms.py index e3c38f7a..f8b8afba 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -34,6 +34,7 @@ class NewFactureForm(ModelForm): 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" + self.fields['paiement'].widget.attrs['data-cheque'] = Paiement.objects.filter(type_paiement=1).first().id class Meta: model = Facture diff --git a/cotisations/models.py b/cotisations/models.py index b716f836..a25ed445 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -172,6 +172,11 @@ class Paiement(models.Model): def clean(self): self.moyen = self.moyen.title() + def save(self, *args, **kwargs): + if Paiement.objects.filter(type_paiement=1).count() > 1: + raise ValidationError("On ne peut avoir plusieurs mode de paiement chèque") + super(Paiement, self).save(*args, **kwargs) + class Cotisation(models.Model): PRETTY_NAME = "Cotisations" diff --git a/cotisations/templates/cotisations/aff_article.html b/cotisations/templates/cotisations/aff_article.html index 11644c8b..b756f746 100644 --- a/cotisations/templates/cotisations/aff_article.html +++ b/cotisations/templates/cotisations/aff_article.html @@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ article.name }} {{ article.prix }} - {{ article.cotisation }} + {{ article.iscotisation }} {{ article.duration }} {% if is_trez %} diff --git a/cotisations/templates/cotisations/new_facture.html b/cotisations/templates/cotisations/new_facture.html index 416ba14f..2dfa52c2 100644 --- a/cotisations/templates/cotisations/new_facture.html +++ b/cotisations/templates/cotisations/new_facture.html @@ -109,9 +109,9 @@ with this program; if not, write to the Free Software Foundation, Inc., } function set_cheque_info_visibility(){ - var paiement = document.getElementById("id_paiement"); - var visible = paiement.value != '' && - paiement.children[paiement.value].dataset['type'] == 'check'; + var visible = document.getElementById("id_paiement").value == document.getElementById("id_paiement").getAttribute('data-cheque'); + p = document.getElementById("id_paiement") + console.log(p); var display = 'none'; if (visible) { display = 'block';