From 656bf4d25eae45331fc02e7b7f6b0444ca0f5d7c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 1 Jun 2023 18:25:54 +0200 Subject: [PATCH] ARE: Taxe apprentissage en float --- app/entreprises/forms.py | 66 ++++++++++--------- app/entreprises/models.py | 2 +- app/entreprises/routes.py | 6 +- .../d84bc592584e_extension_unaccent.py | 17 +++++ 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index dad9cbaf..69ee2d7b 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -36,6 +36,7 @@ from sqlalchemy import text from wtforms import ( BooleanField, DateField, + DecimalField, FieldList, FormField, HiddenField, @@ -125,10 +126,10 @@ class EntrepriseCreationForm(FlaskForm): submit = SubmitField("Enregistrer", render_kw=SUBMIT_MARGE) cancel = SubmitField("Annuler", render_kw=SUBMIT_MARGE) - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False if EntreprisePreferences.get_check_siret() and self.siret.data != "": siret_data = self.siret.data.strip().replace(" ", "") @@ -251,10 +252,10 @@ class SiteCreationForm(FlaskForm): submit = SubmitField("Enregistrer", render_kw=SUBMIT_MARGE) cancel = SubmitField("Annuler", render_kw=SUBMIT_MARGE) - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False site = EntrepriseSite.query.filter_by( entreprise_id=self.hidden_entreprise_id.data, nom=self.nom.data @@ -278,10 +279,10 @@ class SiteModificationForm(FlaskForm): submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) cancel = SubmitField("Annuler", render_kw=SUBMIT_MARGE) - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False site = EntrepriseSite.query.filter( EntrepriseSite.entreprise_id == self.hidden_entreprise_id.data, @@ -344,10 +345,10 @@ class OffreCreationForm(FlaskForm): (dept.id, dept.acronym) for dept in Departement.query.all() ] - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False if len(self.depts.data) < 1: self.depts.errors.append("Choisir au moins un département") @@ -392,10 +393,10 @@ class OffreModificationForm(FlaskForm): (dept.id, dept.acronym) for dept in Departement.query.all() ] - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False if len(self.depts.data) < 1: self.depts.errors.append("Choisir au moins un département") @@ -442,10 +443,10 @@ class CorrespondantCreationForm(FlaskForm): "Notes", required=False, render_kw={"class": "form-control"} ) - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False if not self.telephone.data and not self.mail.data: msg = "Saisir un moyen de contact (mail ou téléphone)" @@ -461,10 +462,10 @@ class CorrespondantsCreationForm(FlaskForm): submit = SubmitField("Enregistrer") cancel = SubmitField("Annuler") - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False correspondant_list = [] for entry in self.correspondants.entries: @@ -531,10 +532,10 @@ class CorrespondantModificationForm(FlaskForm): .all() ] - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False correspondant = EntrepriseCorrespondant.query.filter( EntrepriseCorrespondant.id != self.hidden_correspondant_id.data, @@ -669,12 +670,13 @@ class TaxeApprentissageForm(FlaskForm): ], default=int(datetime.now().strftime("%Y")), ) - montant = IntegerField( + montant = DecimalField( "Montant (*)", validators=[ DataRequired(message=CHAMP_REQUIS), NumberRange( - min=1, + min=0.1, + max=1e8, message="Le montant doit être supérieur à 0", ), ], @@ -684,10 +686,10 @@ class TaxeApprentissageForm(FlaskForm): submit = SubmitField("Enregistrer", render_kw=SUBMIT_MARGE) cancel = SubmitField("Annuler", render_kw=SUBMIT_MARGE) - def validate(self): + def validate(self, extra_validators=None): validate = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False taxe = EntrepriseTaxeApprentissage.query.filter_by( entreprise_id=self.hidden_entreprise_id.data, annee=self.annee.data @@ -737,12 +739,12 @@ class EnvoiOffreForm(FlaskForm): submit = SubmitField("Envoyer") cancel = SubmitField("Annuler") - def validate(self): + def validate(self, extra_validators=None): validate = True list_select = True - if not FlaskForm.validate(self): - validate = False + if not super().validate(extra_validators): + return False for entry in self.responsables.entries: if entry.data: diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 492cafe9..2dc825b8 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -183,7 +183,7 @@ class EntrepriseTaxeApprentissage(db.Model): db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade") ) annee = db.Column(db.Integer) - montant = db.Column(db.Integer) + montant = db.Column(db.Float) notes = db.Column(db.Text) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index f4d33301..f9eac4f9 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -238,7 +238,7 @@ def delete_validation_entreprise(entreprise_id): text=f"Non validation de la fiche entreprise ({entreprise.nom})", ) db.session.add(log) - flash("L'entreprise a été supprimé de la liste des entreprise à valider.") + flash("L'entreprise a été supprimée de la liste des entreprises à valider.") return redirect(url_for("entreprises.validation")) return render_template( "entreprises/form_confirmation.j2", @@ -769,7 +769,7 @@ def delete_taxe_apprentissage(entreprise_id, taxe_id): ) db.session.add(log) db.session.commit() - flash("La taxe d'apprentissage a été supprimé de la liste.") + flash("La taxe d'apprentissage a été supprimée de la liste.") return redirect( url_for("entreprises.fiche_entreprise", entreprise_id=taxe.entreprise_id) ) @@ -965,7 +965,7 @@ def delete_offre(entreprise_id, offre_id): ) db.session.add(log) db.session.commit() - flash("L'offre a été supprimé de la fiche entreprise.") + flash("L'offre a été supprimée de la fiche entreprise.") return redirect( url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id) ) diff --git a/migrations/versions/d84bc592584e_extension_unaccent.py b/migrations/versions/d84bc592584e_extension_unaccent.py index 74d6ded6..041da64c 100644 --- a/migrations/versions/d84bc592584e_extension_unaccent.py +++ b/migrations/versions/d84bc592584e_extension_unaccent.py @@ -47,11 +47,28 @@ def upgrade(): ["id"], ondelete="CASCADE", ) + + # Les montants de taxe en float: + with op.batch_alter_table("are_taxe_apprentissage", schema=None) as batch_op: + batch_op.alter_column( + "montant", + existing_type=sa.INTEGER(), + type_=sa.Float(), + existing_nullable=True, + ) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table("are_taxe_apprentissage", schema=None) as batch_op: + batch_op.alter_column( + "montant", + existing_type=sa.Float(), + type_=sa.INTEGER(), + existing_nullable=True, + ) + with op.batch_alter_table("are_stages_apprentissages", schema=None) as batch_op: batch_op.drop_constraint( "are_stages_apprentissages_etudid_fkey", type_="foreignkey"