From bf738d1706f4082424f82bfefc5bde156ef6508e Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 1 Jun 2023 18:57:55 +0200 Subject: [PATCH] ARE: Fix #637 (form montant taxe) --- app/entreprises/forms.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 69ee2d7be..5bf3e03b7 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -656,6 +656,21 @@ class StageApprentissageCreationForm(FlaskForm): raise ValidationError("Étudiant introuvable (sélectionnez dans la liste)") +class FrenchFloatField(StringField): + "A field allowing to enter . or ," + + def process_formdata(self, valuelist): + "catch incoming data" + if not valuelist: + return + try: + value = valuelist[0].replace(",", ".") + self.data = float(value) + except ValueError as exc: + self.data = None + raise ValueError(self.gettext("Not a valid decimal value.")) from exc + + class TaxeApprentissageForm(FlaskForm): hidden_entreprise_id = HiddenField() annee = IntegerField( @@ -670,15 +685,15 @@ class TaxeApprentissageForm(FlaskForm): ], default=int(datetime.now().strftime("%Y")), ) - montant = DecimalField( + montant = FrenchFloatField( "Montant (*)", validators=[ DataRequired(message=CHAMP_REQUIS), - NumberRange( - min=0.1, - max=1e8, - message="Le montant doit être supérieur à 0", - ), + # NumberRange( + # min=0.1, + # max=1e8, + # message="Le montant doit être supérieur à 0", + # ), ], default=1, )