ARE: Fix #637 (form montant taxe)

This commit is contained in:
Emmanuel Viennet 2023-06-01 18:57:55 +02:00
parent 656bf4d25e
commit bf738d1706

View File

@ -656,6 +656,21 @@ class StageApprentissageCreationForm(FlaskForm):
raise ValidationError("Étudiant introuvable (sélectionnez dans la liste)") 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): class TaxeApprentissageForm(FlaskForm):
hidden_entreprise_id = HiddenField() hidden_entreprise_id = HiddenField()
annee = IntegerField( annee = IntegerField(
@ -670,15 +685,15 @@ class TaxeApprentissageForm(FlaskForm):
], ],
default=int(datetime.now().strftime("%Y")), default=int(datetime.now().strftime("%Y")),
) )
montant = DecimalField( montant = FrenchFloatField(
"Montant (*)", "Montant (*)",
validators=[ validators=[
DataRequired(message=CHAMP_REQUIS), DataRequired(message=CHAMP_REQUIS),
NumberRange( # NumberRange(
min=0.1, # min=0.1,
max=1e8, # max=1e8,
message="Le montant doit être supérieur à 0", # message="Le montant doit être supérieur à 0",
), # ),
], ],
default=1, default=1,
) )