diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index d2e9eb2f..0ab88a86 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -82,6 +82,7 @@ def _build_string_field(label, required=True, render_kw=None): class EntreprisesFilterForm(FlaskForm): active = BooleanField("Afficher les entreprises désactivés") + association = BooleanField("Afficher les associations partenaires") class EntrepriseCreationForm(FlaskForm): @@ -89,6 +90,7 @@ class EntrepriseCreationForm(FlaskForm): "SIRET (*)", render_kw={"placeholder": "Numéro composé de 14 chiffres"}, ) + association = BooleanField("Association") nom_entreprise = _build_string_field("Nom de l'entreprise (*)") adresse = _build_string_field("Adresse de l'entreprise (*)") codepostal = _build_string_field("Code postal de l'entreprise (*)") @@ -168,8 +170,8 @@ class EntrepriseCreationForm(FlaskForm): class EntrepriseModificationForm(FlaskForm): - hidden_entreprise_siret = HiddenField() siret = StringField("SIRET (*)") + association = BooleanField("Association") nom = _build_string_field("Nom de l'entreprise (*)") adresse = _build_string_field("Adresse (*)") codepostal = _build_string_field("Code postal (*)") @@ -179,10 +181,7 @@ class EntrepriseModificationForm(FlaskForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.siret.render_kw = { - "disabled": "", - "value": self.hidden_entreprise_siret.data, - } + self.siret.render_kw = {"disabled": ""} class SiteCreationForm(FlaskForm): @@ -624,6 +623,7 @@ class TaxeApprentissageForm(FlaskForm): validators=[ DataRequired(message=CHAMP_REQUIS), NumberRange( + min=1900, max=int(datetime.now().strftime("%Y")), message=f"L'année doit être inférieure ou égale à {int(datetime.now().strftime('%Y'))}", ), @@ -661,6 +661,28 @@ class TaxeApprentissageForm(FlaskForm): return validate +class TaxeApprentissageModificationForm(FlaskForm): + hidden_annee = HiddenField() + annee = IntegerField("Année (*)") + montant = IntegerField( + "Montant (*)", + validators=[ + DataRequired(message=CHAMP_REQUIS), + NumberRange( + min=1, + message="Le montant doit être supérieur à 0", + ), + ], + default=1, + ) + notes = TextAreaField("Notes") + submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.annee.render_kw = {"disabled": ""} + + class EnvoiOffreForm(FlaskForm): responsables = FieldList( _build_string_field( diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 4ff35800..72975a64 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -10,6 +10,7 @@ class Entreprise(db.Model): codepostal = db.Column(db.Text) ville = db.Column(db.Text) pays = db.Column(db.Text) + association = db.Column(db.Boolean, default=False) visible = db.Column(db.Boolean, default=False) active = db.Column(db.Boolean, default=True) notes_active = db.Column(db.Text) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index c0f47382..be88e2ad 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -31,6 +31,7 @@ from app.entreprises.forms import ( EnvoiOffreForm, AjoutFichierForm, TaxeApprentissageForm, + TaxeApprentissageModificationForm, ValidationConfirmationForm, ImportForm, PreferencesForm, @@ -71,11 +72,14 @@ def index(): logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all() if current_user.has_permission(Permission.RelationsEntreprisesChange, None): form = EntreprisesFilterForm() - checked = False + checked = [False, False] if request.method == "POST": - checked = form.active.data - if checked: + checked[0] = form.active.data + checked[1] = form.association.data + if checked[0]: entreprises = Entreprise.query.filter_by(visible=True) + if checked[1]: + entreprises = Entreprise.query.filter_by(association=True) return render_template( "entreprises/entreprises.html", title="Entreprises", @@ -317,6 +321,7 @@ def add_entreprise(): entreprise = Entreprise( nom=form.nom_entreprise.data.strip(), siret=form.siret.data.strip(), + association=form.association.data, adresse=form.adresse.data.strip(), codepostal=form.codepostal.data.strip(), ville=form.ville.data.strip(), @@ -387,7 +392,7 @@ def edit_entreprise(id): entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( description=f"entreprise {id} inconnue" ) - form = EntrepriseModificationForm(hidden_entreprise_siret=entreprise.siret) + form = EntrepriseModificationForm(siret=entreprise.siret) if form.validate_on_submit(): nom_entreprise = f"{form.nom.data.strip()}" if entreprise.nom != form.nom.data.strip(): @@ -432,6 +437,7 @@ def edit_entreprise(id): form.pays.data.strip() if form.pays.data.strip() else "FRANCE" ) db.session.add(log) + entreprise.association = form.association.data db.session.commit() flash("L'entreprise a été modifié.") return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) @@ -442,6 +448,7 @@ def edit_entreprise(id): form.codepostal.data = entreprise.codepostal form.ville.data = entreprise.ville form.pays.data = entreprise.pays + form.association.data = entreprise.association return render_template( "entreprises/form_modification_entreprise.html", title="Modification entreprise", @@ -522,6 +529,64 @@ def add_taxe_apprentissage(id): ) +@bp.route( + "/fiche_entreprise//edit_taxe_apprentissage/", + methods=["GET", "POST"], +) +def edit_taxe_apprentissage(id_entreprise, id_taxe): + """ + Permet de modifier une taxe d'apprentissage sur un fiche entreprise + """ + entreprise = Entreprise.query.filter_by( + id=id_entreprise, visible=True + ).first_or_404(description=f"entreprise {id_entreprise} inconnue") + taxe = EntrepriseTaxeApprentissage.query.filter_by(id=id_taxe).first_or_404( + description=f"taxe d'apprentissage {id_taxe} inconnue" + ) + form = TaxeApprentissageModificationForm(annee=taxe.annee) + if form.validate_on_submit(): + taxe.montant = form.montant.data + taxe.notes = form.notes.data.strip() + db.session.commit() + return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) + elif request.method == "GET": + form.montant.data = taxe.montant + form.notes.data = taxe.notes + return render_template( + "entreprises/form.html", + title="Modification taxe apprentissage", + form=form, + ) + + +@bp.route( + "/fiche_entreprise//delete_taxe_apprentissage/", + methods=["GET", "POST"], +) +def delete_taxe_apprentissage(id_entreprise, id_taxe): + """ + Permet de modifier une taxe d'apprentissage sur un fiche entreprise + """ + entreprise = Entreprise.query.filter_by( + id=id_entreprise, visible=True + ).first_or_404(description=f"entreprise {id_entreprise} inconnue") + taxe = EntrepriseTaxeApprentissage.query.filter_by(id=id_taxe).first_or_404( + description=f"taxe d'apprentissage {id_taxe} inconnue" + ) + form = SuppressionConfirmationForm() + if form.validate_on_submit(): + db.session.delete(taxe) + db.session.commit() + flash("La taxe d'apprentissage a été supprimé de la liste.") + return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) + return render_template( + "entreprises/confirmation_form.html", + title="Supprimer taxe apprentissage", + form=form, + info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression", + ) + + @bp.route( "/fiche_entreprise_validation//validate_entreprise", methods=["GET", "POST"] ) diff --git a/app/static/css/entreprises.css b/app/static/css/entreprises.css index 286381d6..702cee93 100644 --- a/app/static/css/entreprises.css +++ b/app/static/css/entreprises.css @@ -115,4 +115,9 @@ border: solid 2px; border-radius: 10px; padding: 10px; +} + +#liste-taxes-apprentissages { + list-style: none; + padding-left: 0; } \ No newline at end of file diff --git a/app/templates/entreprises/entreprises.html b/app/templates/entreprises/entreprises.html index a45113de..e755d1d8 100644 --- a/app/templates/entreprises/entreprises.html +++ b/app/templates/entreprises/entreprises.html @@ -39,7 +39,8 @@ {% if form %}
{{ form.hidden_tag() }} - + +
{% endif %} diff --git a/app/templates/entreprises/fiche_entreprise.html b/app/templates/entreprises/fiche_entreprise.html index b8a1bf89..74fa3239 100644 --- a/app/templates/entreprises/fiche_entreprise.html +++ b/app/templates/entreprises/fiche_entreprise.html @@ -33,7 +33,10 @@ Adresse : {{ entreprise.adresse }}
Code postal : {{ entreprise.codepostal }}
Ville : {{ entreprise.ville }}
- Pays : {{ entreprise.pays }} + Pays : {{ entreprise.pays }}
+ {% if entreprise.association %} + Association + {% endif %} {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} @@ -41,12 +44,15 @@ Taxe d'apprentissage
Ajouter taxe apprentissage
-
    +
      {% if not taxes|check_taxe_now %}
    • année actuelle : non versé
    • {% endif %} {% for taxe in taxes %} -
    • {{ taxe.annee }} : {{ taxe.montant }} euros
    • +
    • + supprimer + {{ taxe.annee }} : {{ taxe.montant }} euros +
    • {% endfor %}
diff --git a/app/templates/entreprises/fiche_entreprise_validation.html b/app/templates/entreprises/fiche_entreprise_validation.html index 2f243b24..f980a17f 100644 --- a/app/templates/entreprises/fiche_entreprise_validation.html +++ b/app/templates/entreprises/fiche_entreprise_validation.html @@ -12,7 +12,10 @@ Adresse : {{ entreprise.adresse }}
Code postal : {{ entreprise.codepostal }}
Ville : {{ entreprise.ville }}
- Pays : {{ entreprise.pays }} + Pays : {{ entreprise.pays }}
+ {% if entreprise.association %} + Association + {% endif %}