2021-12-27 19:00:38 +01:00
|
|
|
import os
|
2023-04-06 16:10:32 +02:00
|
|
|
from datetime import datetime
|
2021-12-28 21:20:50 +01:00
|
|
|
import glob
|
|
|
|
import shutil
|
2021-12-27 19:00:38 +01:00
|
|
|
|
2021-12-27 11:48:58 +01:00
|
|
|
from flask import render_template, redirect, url_for, request, flash, send_file, abort
|
2023-04-06 16:10:32 +02:00
|
|
|
from flask_json import as_json
|
2021-12-23 19:28:25 +01:00
|
|
|
from flask_login import current_user
|
2023-04-06 16:10:32 +02:00
|
|
|
from sqlalchemy import text, sql
|
|
|
|
from werkzeug.utils import secure_filename
|
2021-12-27 11:48:58 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.decorators import permission_required
|
2021-12-24 18:10:19 +01:00
|
|
|
|
2022-07-13 12:14:00 +02:00
|
|
|
from app.entreprises import LOGS_LEN, SIRET_PROVISOIRE_START
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.entreprises.forms import (
|
2022-05-02 14:36:39 +02:00
|
|
|
ActivationConfirmationForm,
|
2022-04-07 02:54:11 +02:00
|
|
|
CorrespondantsCreationForm,
|
2022-04-21 21:18:47 +02:00
|
|
|
DesactivationConfirmationForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
EntrepriseCreationForm,
|
|
|
|
EntrepriseModificationForm,
|
2022-05-02 14:36:39 +02:00
|
|
|
EntreprisesFilterForm,
|
2022-04-25 20:49:21 +02:00
|
|
|
SiteCreationForm,
|
2022-04-28 23:04:31 +02:00
|
|
|
SiteModificationForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
SuppressionConfirmationForm,
|
|
|
|
OffreCreationForm,
|
|
|
|
OffreModificationForm,
|
2022-03-28 23:44:57 +02:00
|
|
|
CorrespondantModificationForm,
|
2022-04-05 02:26:43 +02:00
|
|
|
ContactCreationForm,
|
|
|
|
ContactModificationForm,
|
2022-03-28 23:44:57 +02:00
|
|
|
StageApprentissageCreationForm,
|
2021-12-28 21:20:50 +01:00
|
|
|
EnvoiOffreForm,
|
|
|
|
AjoutFichierForm,
|
2022-05-04 18:59:29 +02:00
|
|
|
TaxeApprentissageForm,
|
2022-05-06 01:33:50 +02:00
|
|
|
TaxeApprentissageModificationForm,
|
2022-02-01 18:35:48 +01:00
|
|
|
ValidationConfirmationForm,
|
2022-02-10 21:17:22 +01:00
|
|
|
ImportForm,
|
2022-02-22 21:52:32 +01:00
|
|
|
PreferencesForm,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
from app.entreprises import bp
|
|
|
|
from app.entreprises.models import (
|
|
|
|
Entreprise,
|
|
|
|
EntrepriseOffre,
|
2022-03-28 23:44:57 +02:00
|
|
|
EntrepriseCorrespondant,
|
2022-07-04 21:12:56 +02:00
|
|
|
EntrepriseHistorique,
|
2022-04-05 02:26:43 +02:00
|
|
|
EntrepriseContact,
|
2022-04-25 20:49:21 +02:00
|
|
|
EntrepriseSite,
|
2022-03-28 23:44:57 +02:00
|
|
|
EntrepriseStageApprentissage,
|
2021-12-28 21:20:50 +01:00
|
|
|
EntrepriseEnvoiOffre,
|
2022-02-03 18:07:16 +01:00
|
|
|
EntrepriseOffreDepartement,
|
2022-02-22 21:52:32 +01:00
|
|
|
EntreprisePreferences,
|
2022-05-04 18:59:29 +02:00
|
|
|
EntrepriseTaxeApprentissage,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-02-15 18:24:10 +01:00
|
|
|
from app.entreprises import app_relations_entreprises as are
|
2021-12-28 21:20:50 +01:00
|
|
|
from app.models import Identite
|
2021-12-23 19:28:25 +01:00
|
|
|
from app.auth.models import User
|
2021-12-27 11:48:58 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2021-12-24 18:10:19 +01:00
|
|
|
from app.scodoc import sco_etud, sco_excel
|
|
|
|
import app.scodoc.sco_utils as scu
|
2021-12-27 11:48:58 +01:00
|
|
|
|
|
|
|
from app import db
|
2023-04-06 16:10:32 +02:00
|
|
|
from config import Config
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-05-02 14:36:39 +02:00
|
|
|
@bp.route("/", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2021-12-23 19:28:25 +01:00
|
|
|
def index():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-08-10 02:27:52 +02:00
|
|
|
Permet d'afficher une page avec la liste des entreprises (visible et active) et une liste des dernières opérations
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-04-20 22:37:04 +02:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=True, active=True)
|
2022-07-04 21:12:56 +02:00
|
|
|
logs = (
|
|
|
|
EntrepriseHistorique.query.order_by(EntrepriseHistorique.date.desc())
|
|
|
|
.limit(LOGS_LEN)
|
|
|
|
.all()
|
|
|
|
)
|
2022-07-20 18:24:15 +02:00
|
|
|
form = EntreprisesFilterForm()
|
|
|
|
checked = [False, False, False]
|
|
|
|
if request.method == "POST":
|
|
|
|
checked = [form.active.data, form.association.data, form.siret_provisoire.data]
|
|
|
|
if checked[0]:
|
|
|
|
entreprises = Entreprise.query.filter_by(visible=True)
|
|
|
|
if checked[1]:
|
2022-08-10 02:27:52 +02:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=True, association=True)
|
2022-07-20 18:24:15 +02:00
|
|
|
if checked[2]:
|
2022-08-10 02:27:52 +02:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=True, siret_provisoire=True)
|
2022-07-20 18:24:15 +02:00
|
|
|
if checked[1] and checked[2]:
|
|
|
|
entreprises = Entreprise.query.filter_by(
|
2022-08-10 02:27:52 +02:00
|
|
|
visible=True, association=True, siret_provisoire=True
|
2022-05-02 14:36:39 +02:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/entreprises.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Entreprises",
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprises=entreprises,
|
|
|
|
logs=logs,
|
2022-07-20 18:24:15 +02:00
|
|
|
form=form,
|
|
|
|
checked=checked,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-01-31 18:22:54 +01:00
|
|
|
@bp.route("/logs", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-01-31 18:22:54 +01:00
|
|
|
def logs():
|
|
|
|
"""
|
|
|
|
Permet d'afficher les logs (toutes les entreprises)
|
|
|
|
"""
|
|
|
|
page = request.args.get("page", 1, type=int)
|
2022-07-04 21:12:56 +02:00
|
|
|
logs = EntrepriseHistorique.query.order_by(
|
|
|
|
EntrepriseHistorique.date.desc()
|
|
|
|
).paginate(page=page, per_page=20)
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/logs.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Logs",
|
2022-02-08 16:40:32 +01:00
|
|
|
logs=logs,
|
|
|
|
)
|
2022-01-31 18:22:54 +01:00
|
|
|
|
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
@bp.route("/correspondants", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepViewCorrs)
|
2022-03-28 23:44:57 +02:00
|
|
|
def correspondants():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'afficher une page avec la liste des correspondants des entreprises visibles et une liste des dernières opérations
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondants = (
|
2022-04-28 23:04:31 +02:00
|
|
|
db.session.query(EntrepriseCorrespondant, EntrepriseSite)
|
|
|
|
.join(EntrepriseSite, EntrepriseCorrespondant.site_id == EntrepriseSite.id)
|
|
|
|
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
|
2022-04-21 21:18:47 +02:00
|
|
|
.filter_by(visible=True, active=True)
|
2022-05-31 19:15:24 +02:00
|
|
|
.all()
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2022-07-04 21:12:56 +02:00
|
|
|
logs = (
|
|
|
|
EntrepriseHistorique.query.order_by(EntrepriseHistorique.date.desc())
|
|
|
|
.limit(LOGS_LEN)
|
|
|
|
.all()
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/correspondants.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Correspondants",
|
|
|
|
correspondants=correspondants,
|
2022-02-08 16:40:32 +01:00
|
|
|
logs=logs,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route("/validation", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepValidate)
|
2022-08-23 18:54:44 +02:00
|
|
|
def validation():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
Permet d'afficher une page avec la liste des entreprises a valider (non visible)
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
entreprises = Entreprise.query.filter_by(visible=False).all()
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/entreprises_validation.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Validation entreprises",
|
|
|
|
entreprises=entreprises,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route("/fiche_entreprise_validation/<int:entreprise_id>", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepValidate)
|
2022-08-23 18:54:44 +02:00
|
|
|
def fiche_entreprise_validation(entreprise_id):
|
2022-02-02 19:13:50 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
Permet d'afficher la fiche entreprise d'une entreprise a valider
|
2022-02-02 19:13:50 +01:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
2022-08-23 18:54:44 +02:00
|
|
|
id=entreprise_id, visible=False
|
|
|
|
).first_or_404(
|
|
|
|
description=f"fiche entreprise (validation) {entreprise_id} inconnue"
|
2022-02-02 19:13:50 +01:00
|
|
|
)
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/fiche_entreprise_validation.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Validation fiche entreprise",
|
2022-02-02 19:13:50 +01:00
|
|
|
entreprise=entreprise,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise_validation/<int:entreprise_id>/validate_entreprise",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepValidate)
|
2022-08-23 18:54:44 +02:00
|
|
|
def validate_entreprise(entreprise_id):
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
Permet de valider une entreprise
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
form = ValidationConfirmationForm()
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=False
|
2022-08-23 18:54:44 +02:00
|
|
|
).first_or_404(description=f"entreprise (validation) {entreprise_id} inconnue")
|
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise_validation", entreprise_id=entreprise_id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise.visible = True
|
|
|
|
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
text=f"{nom_entreprise} - Validation de la fiche entreprise ({entreprise.nom})",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été validé et ajouté à la liste.")
|
|
|
|
return redirect(url_for("entreprises.validation"))
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_validate_confirmation.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Validation entreprise",
|
|
|
|
form=form,
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-08-23 18:54:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise_validation/<int:entreprise_id>/delete_validation_entreprise",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepValidate)
|
2022-08-23 18:54:44 +02:00
|
|
|
def delete_validation_entreprise(entreprise_id):
|
|
|
|
"""
|
|
|
|
Permet de supprimer une entreprise en attente de validation avec une formulaire de validation
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=False
|
|
|
|
).first_or_404(description=f"entreprise (validation) {entreprise_id} inconnue")
|
|
|
|
form = SuppressionConfirmationForm()
|
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise_validation", entreprise_id=entreprise_id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(entreprise)
|
|
|
|
db.session.commit()
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
text=f"Non validation de la fiche entreprise ({entreprise.nom})",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2023-06-01 18:25:54 +02:00
|
|
|
flash("L'entreprise a été supprimée de la liste des entreprises à valider.")
|
2022-08-23 18:54:44 +02:00
|
|
|
return redirect(url_for("entreprises.validation"))
|
2022-01-26 18:42:48 +01:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Supression entreprise",
|
|
|
|
form=form,
|
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2022-01-26 18:42:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-25 19:42:17 +01:00
|
|
|
@bp.route("/offres_recues", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-01-27 16:28:28 +01:00
|
|
|
def offres_recues():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'afficher la page où l'on peut voir les offres reçues
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
offres_recues = (
|
2021-12-28 21:20:50 +01:00
|
|
|
db.session.query(EntrepriseEnvoiOffre, EntrepriseOffre)
|
|
|
|
.filter(EntrepriseEnvoiOffre.receiver_id == current_user.id)
|
|
|
|
.join(EntrepriseOffre, EntrepriseOffre.id == EntrepriseEnvoiOffre.offre_id)
|
|
|
|
.all()
|
|
|
|
)
|
2022-02-01 18:35:48 +01:00
|
|
|
offres_recues_with_files = []
|
2022-08-16 18:34:08 +02:00
|
|
|
for envoi_offre, offre in offres_recues:
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant = EntrepriseCorrespondant.query.filter_by(
|
2022-08-16 18:34:08 +02:00
|
|
|
id=offre.correspondant_id
|
2022-03-28 23:44:57 +02:00
|
|
|
).first()
|
2022-02-01 18:35:48 +01:00
|
|
|
files = []
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
2022-08-16 18:34:08 +02:00
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre.id}",
|
2022-02-01 18:35:48 +01:00
|
|
|
)
|
|
|
|
if os.path.exists(path):
|
|
|
|
for dir in glob.glob(
|
|
|
|
f"{path}/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"
|
|
|
|
):
|
|
|
|
for file in glob.glob(f"{dir}/*"):
|
|
|
|
file = [os.path.basename(dir), os.path.basename(file)]
|
|
|
|
files.append(file)
|
2022-08-16 18:34:08 +02:00
|
|
|
offres_recues_with_files.append([envoi_offre, offre, files, correspondant])
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/offres_recues.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Offres reçues",
|
2022-02-01 18:35:48 +01:00
|
|
|
offres_recues=offres_recues_with_files,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-24 16:07:36 +01:00
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route(
|
|
|
|
"/offres_recues/delete_offre_recue/<int:envoi_offre_id>", methods=["GET", "POST"]
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-08-23 18:54:44 +02:00
|
|
|
def delete_offre_recue(envoi_offre_id):
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
Permet de supprimer une offre reçue
|
2022-01-31 18:22:54 +01:00
|
|
|
"""
|
2022-08-23 18:54:44 +02:00
|
|
|
offre_recue = EntrepriseEnvoiOffre.query.filter_by(
|
|
|
|
id=envoi_offre_id, receiver_id=current_user.id
|
|
|
|
).first_or_404(description=f"offre recu {envoi_offre_id} inconnue")
|
|
|
|
db.session.delete(offre_recue)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(url_for("entreprises.offres_recues"))
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/preferences", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepValidate)
|
2022-08-23 18:54:44 +02:00
|
|
|
def preferences():
|
|
|
|
"""
|
|
|
|
Permet d'afficher la page des préférences du module gestion des relations entreprises
|
|
|
|
"""
|
|
|
|
form = PreferencesForm()
|
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
if form.validate_on_submit():
|
|
|
|
EntreprisePreferences.set_email_notifications(form.mail_entreprise.data.strip())
|
|
|
|
EntreprisePreferences.set_check_siret(int(form.check_siret.data))
|
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
elif request.method == "GET":
|
|
|
|
form.mail_entreprise.data = EntreprisePreferences.get_email_notifications()
|
|
|
|
form.check_siret.data = int(EntreprisePreferences.get_check_siret())
|
2022-01-24 19:02:16 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/preferences.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Préférences",
|
|
|
|
form=form,
|
2022-01-24 19:02:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/add_entreprise", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2021-12-23 19:28:25 +01:00
|
|
|
def add_entreprise():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter une entreprise dans la base avec un formulaire
|
|
|
|
"""
|
2021-12-23 19:28:25 +01:00
|
|
|
form = EntrepriseCreationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(url_for("entreprises.index"))
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise = Entreprise(
|
|
|
|
nom=form.nom_entreprise.data.strip(),
|
2022-07-13 12:14:00 +02:00
|
|
|
siret=form.siret.data.strip()
|
|
|
|
if form.siret.data.strip()
|
|
|
|
else f"{SIRET_PROVISOIRE_START}{datetime.now().strftime('%d%m%y%H%M%S')}", # siret provisoire
|
|
|
|
siret_provisoire=False if form.siret.data.strip() else True,
|
2022-05-06 01:33:50 +02:00
|
|
|
association=form.association.data,
|
2021-12-23 19:28:25 +01:00
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
2022-02-28 18:57:05 +01:00
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-07-13 16:53:54 +02:00
|
|
|
try:
|
|
|
|
db.session.add(entreprise)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(entreprise)
|
|
|
|
except:
|
|
|
|
db.session.rollback()
|
|
|
|
flash("Une erreur est survenue veuillez réessayer.")
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_ajout_entreprise.j2",
|
2022-07-13 16:53:54 +02:00
|
|
|
title="Ajout entreprise avec correspondant",
|
|
|
|
form=form,
|
|
|
|
)
|
2022-04-25 20:49:21 +02:00
|
|
|
site = EntrepriseSite(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
nom=form.nom_entreprise.data.strip(),
|
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
|
|
|
)
|
|
|
|
db.session.add(site)
|
|
|
|
db.session.commit()
|
2022-04-13 20:59:26 +02:00
|
|
|
if form.nom_correspondant.data.strip():
|
2022-04-25 20:49:21 +02:00
|
|
|
db.session.refresh(site)
|
2022-04-13 20:59:26 +02:00
|
|
|
correspondant = EntrepriseCorrespondant(
|
2022-04-25 20:49:21 +02:00
|
|
|
site_id=site.id,
|
2022-04-20 22:37:04 +02:00
|
|
|
civilite=form.civilite.data,
|
2022-04-13 20:59:26 +02:00
|
|
|
nom=form.nom_correspondant.data.strip(),
|
|
|
|
prenom=form.prenom_correspondant.data.strip(),
|
|
|
|
telephone=form.telephone.data.strip(),
|
|
|
|
mail=form.mail.data.strip(),
|
|
|
|
poste=form.poste.data.strip(),
|
|
|
|
service=form.service.data.strip(),
|
2022-04-20 22:37:04 +02:00
|
|
|
origine=form.origine.data.strip(),
|
|
|
|
notes=form.notes.data.strip(),
|
2022-04-13 20:59:26 +02:00
|
|
|
)
|
|
|
|
db.session.add(correspondant)
|
2023-09-29 21:17:31 +02:00
|
|
|
if current_user.has_permission(Permission.RelationsEntrepValidate, None):
|
2022-02-02 19:13:50 +01:00
|
|
|
entreprise.visible = True
|
2022-07-13 16:53:54 +02:00
|
|
|
lien_entreprise = f"<a href='{url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id)}'>{entreprise.nom}</a>"
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2022-02-02 19:13:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-07-08 18:56:27 +02:00
|
|
|
text=f"{lien_entreprise} - Création de la fiche entreprise ({entreprise.nom})",
|
2022-05-06 18:50:12 +02:00
|
|
|
entreprise_id=entreprise.id,
|
2022-02-02 19:13:50 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été ajouté à la liste.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
|
|
|
else:
|
|
|
|
entreprise.visible = False
|
|
|
|
db.session.commit()
|
2022-02-23 19:12:26 +01:00
|
|
|
if EntreprisePreferences.get_email_notifications():
|
|
|
|
are.send_email_notifications_entreprise(
|
2022-04-12 00:21:25 +02:00
|
|
|
"entreprise en attente de validation", entreprise
|
2022-02-23 19:12:26 +01:00
|
|
|
)
|
2022-02-02 19:13:50 +01:00
|
|
|
flash("L'entreprise a été ajouté à la liste pour la validation.")
|
|
|
|
return redirect(url_for("entreprises.index"))
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_ajout_entreprise.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Ajout entreprise avec correspondant",
|
2021-12-28 21:20:50 +01:00
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-08-23 18:54:44 +02:00
|
|
|
def fiche_entreprise(entreprise_id):
|
|
|
|
"""
|
|
|
|
Permet d'afficher la fiche entreprise d'une entreprise avec une liste des dernières opérations et
|
|
|
|
l'historique des étudiants ayant réaliser un stage ou une alternance dans cette entreprise.
|
|
|
|
La fiche entreprise comporte les informations de l'entreprise, les correspondants de l'entreprise et
|
|
|
|
les offres de l'entreprise.
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"fiche entreprise {entreprise_id} inconnue")
|
|
|
|
offres_with_files = are.get_offres_non_expirees_with_files(entreprise.offres)
|
|
|
|
logs = (
|
|
|
|
EntrepriseHistorique.query.order_by(EntrepriseHistorique.date.desc())
|
|
|
|
.filter(EntrepriseHistorique.entreprise_id == entreprise.id)
|
|
|
|
.limit(LOGS_LEN)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
stages_apprentissages = (
|
|
|
|
db.session.query(EntrepriseStageApprentissage, Identite)
|
|
|
|
.order_by(EntrepriseStageApprentissage.date_debut.desc())
|
|
|
|
.filter(EntrepriseStageApprentissage.entreprise_id == entreprise.id)
|
|
|
|
.join(Identite, Identite.id == EntrepriseStageApprentissage.etudid)
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
taxes = (
|
|
|
|
EntrepriseTaxeApprentissage.query.filter_by(entreprise_id=entreprise.id)
|
|
|
|
.order_by(EntrepriseTaxeApprentissage.annee.desc())
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/fiche_entreprise.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Fiche entreprise",
|
|
|
|
entreprise=entreprise,
|
|
|
|
offres=offres_with_files,
|
|
|
|
logs=logs,
|
|
|
|
stages_apprentissages=stages_apprentissages,
|
|
|
|
taxes=taxes,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/logs", methods=["GET"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-08-23 18:54:44 +02:00
|
|
|
def logs_entreprise(entreprise_id):
|
|
|
|
"""
|
|
|
|
Permet d'afficher les logs d'une entreprise
|
|
|
|
"""
|
|
|
|
page = request.args.get("page", 1, type=int)
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"logs fiche entreprise {entreprise_id} inconnu")
|
|
|
|
logs = (
|
|
|
|
EntrepriseHistorique.query.order_by(EntrepriseHistorique.date.desc())
|
|
|
|
.filter(EntrepriseHistorique.entreprise_id == entreprise.id)
|
|
|
|
.paginate(page=page, per_page=20)
|
|
|
|
)
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/logs_entreprise.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Logs",
|
|
|
|
logs=logs,
|
|
|
|
entreprise=entreprise,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/offres_expirees")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-08-23 18:54:44 +02:00
|
|
|
def offres_expirees(entreprise_id):
|
|
|
|
"""
|
|
|
|
Permet d'afficher la liste des offres expirés d'une entreprise
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"fiche entreprise {entreprise_id} inconnue")
|
|
|
|
offres_with_files = are.get_offres_expirees_with_files(entreprise.offres)
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/offres_expirees.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Offres expirées",
|
|
|
|
entreprise=entreprise,
|
|
|
|
offres_expirees=offres_with_files,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/edit_entreprise", methods=["GET", "POST"]
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_entreprise(entreprise_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de modifier une entreprise de la base avec un formulaire
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
2022-05-06 01:33:50 +02:00
|
|
|
form = EntrepriseModificationForm(siret=entreprise.siret)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-07-13 16:53:54 +02:00
|
|
|
lien_entreprise = f"<a href='{url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id)}'>{form.nom.data.strip()}</a>"
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text = []
|
2022-07-13 12:14:00 +02:00
|
|
|
if form.new_siret.data:
|
|
|
|
logs_text.append(f"{lien_entreprise} - Modification du SIRET")
|
|
|
|
entreprise.siret = form.new_siret.data.strip()
|
2022-07-20 18:24:15 +02:00
|
|
|
entreprise.siret_provisoire = False
|
2021-12-23 19:28:25 +01:00
|
|
|
if entreprise.nom != form.nom.data.strip():
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text.append(
|
|
|
|
f"{lien_entreprise} - Modification du nom (ancien nom: {entreprise.nom})"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.nom = form.nom.data.strip()
|
2022-07-08 18:56:27 +02:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
if entreprise.adresse != form.adresse.data.strip():
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text.append(
|
|
|
|
f"{lien_entreprise} - Modification de l'adresse (ancienne adresse: {entreprise.adresse})"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.adresse = form.adresse.data.strip()
|
2022-07-08 18:56:27 +02:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
if entreprise.codepostal != form.codepostal.data.strip():
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text.append(
|
|
|
|
f"{lien_entreprise} - Modification du code postal (ancien code postal: {entreprise.codepostal})"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.codepostal = form.codepostal.data.strip()
|
2022-07-08 18:56:27 +02:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
if entreprise.ville != form.ville.data.strip():
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text.append(
|
|
|
|
f"{lien_entreprise} - Modification de la ville (ancienne ville: {entreprise.ville})"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
entreprise.ville = form.ville.data.strip()
|
2022-07-08 18:56:27 +02:00
|
|
|
|
2022-02-28 18:57:05 +01:00
|
|
|
if entreprise.pays != form.pays.data.strip() or not form.pays.data.strip():
|
2022-07-08 18:56:27 +02:00
|
|
|
logs_text.append(
|
|
|
|
f"{lien_entreprise} - Modification du pays (ancien pays: {entreprise.pays})"
|
2022-02-28 18:57:05 +01:00
|
|
|
)
|
|
|
|
entreprise.pays = (
|
|
|
|
form.pays.data.strip() if form.pays.data.strip() else "FRANCE"
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-07-08 18:56:27 +02:00
|
|
|
|
2022-05-06 01:33:50 +02:00
|
|
|
entreprise.association = form.association.data
|
2022-07-08 18:56:27 +02:00
|
|
|
for log_text in logs_text:
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
text=log_text,
|
2022-07-08 18:56:27 +02:00
|
|
|
)
|
2022-07-20 18:24:15 +02:00
|
|
|
db.session.add(log)
|
2021-12-23 19:28:25 +01:00
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été modifié.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
elif request.method == "GET":
|
2021-12-23 19:28:25 +01:00
|
|
|
form.siret.data = entreprise.siret
|
|
|
|
form.nom.data = entreprise.nom
|
|
|
|
form.adresse.data = entreprise.adresse
|
|
|
|
form.codepostal.data = entreprise.codepostal
|
|
|
|
form.ville.data = entreprise.ville
|
|
|
|
form.pays.data = entreprise.pays
|
2022-05-06 01:33:50 +02:00
|
|
|
form.association.data = entreprise.association
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_modification_entreprise.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Modification entreprise",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/desactiver", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def fiche_entreprise_desactiver(entreprise_id):
|
2022-04-21 21:18:47 +02:00
|
|
|
"""
|
|
|
|
Permet de désactiver une entreprise
|
|
|
|
"""
|
2022-05-02 14:36:39 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
2022-07-11 16:06:38 +02:00
|
|
|
id=entreprise_id, visible=True, active=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
2022-04-21 21:18:47 +02:00
|
|
|
form = DesactivationConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-04-21 21:18:47 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise.notes_active = form.notes_active.data.strip()
|
|
|
|
entreprise.active = False
|
2022-07-20 18:24:15 +02:00
|
|
|
lien_entreprise = f"<a href='{url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id)}'>{entreprise.nom}</a>"
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
text=f"{lien_entreprise} - Désactivation fiche entreprise",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-04-21 21:18:47 +02:00
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été désactivé.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2022-04-21 21:18:47 +02:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-04-21 21:18:47 +02:00
|
|
|
title="Désactiver entreprise",
|
|
|
|
form=form,
|
2022-05-02 14:36:39 +02:00
|
|
|
info_message="Cliquez sur le bouton Modifier pour confirmer la désactivation",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/activer", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def fiche_entreprise_activer(entreprise_id):
|
2022-05-02 14:36:39 +02:00
|
|
|
"""
|
|
|
|
Permet d'activer une entreprise
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
2022-07-11 16:06:38 +02:00
|
|
|
id=entreprise_id, visible=True, active=False
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
2022-05-02 14:36:39 +02:00
|
|
|
form = ActivationConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-05-02 14:36:39 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
entreprise.active = True
|
2022-07-20 18:24:15 +02:00
|
|
|
lien_entreprise = f"<a href='{url_for('entreprises.fiche_entreprise', entreprise_id=entreprise.id)}'>{entreprise.nom}</a>"
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
text=f"{lien_entreprise} - Activation fiche entreprise",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-05-02 14:36:39 +02:00
|
|
|
db.session.commit()
|
|
|
|
flash("L'entreprise a été activé.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2022-05-02 14:36:39 +02:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-05-02 14:36:39 +02:00
|
|
|
title="Activer entreprise",
|
|
|
|
form=form,
|
|
|
|
info_message="Cliquez sur le bouton Modifier pour confirmer l'activaction",
|
2022-04-21 21:18:47 +02:00
|
|
|
)
|
2022-04-20 22:37:04 +02:00
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/add_taxe_apprentissage",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
|
|
|
def add_taxe_apprentissage(entreprise_id):
|
2022-05-04 18:59:29 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
Permet d'ajouter une taxe d'apprentissage sur une fiche entreprise
|
2022-05-04 18:59:29 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
|
|
|
form = TaxeApprentissageForm(hidden_entreprise_id=entreprise.id)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-05-04 18:59:29 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
taxe = EntrepriseTaxeApprentissage(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
annee=form.annee.data,
|
|
|
|
montant=form.montant.data,
|
|
|
|
notes=form.notes.data.strip(),
|
|
|
|
)
|
|
|
|
db.session.add(taxe)
|
|
|
|
db.session.commit()
|
2022-07-20 18:24:15 +02:00
|
|
|
db.session.refresh(taxe)
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
object="taxe apprentissage",
|
|
|
|
object_id=taxe.id,
|
|
|
|
text=f"Création d'une taxe d'apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2022-05-04 18:59:29 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-05-04 18:59:29 +02:00
|
|
|
title="Ajout taxe apprentissage",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-05-06 01:33:50 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/edit_taxe_apprentissage/<int:taxe_id>",
|
2022-05-06 01:33:50 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_taxe_apprentissage(entreprise_id, taxe_id):
|
2022-05-06 01:33:50 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
Permet de modifier une taxe d'apprentissage sur une fiche entreprise
|
2022-05-06 01:33:50 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
taxe = EntrepriseTaxeApprentissage.query.filter_by(
|
|
|
|
id=taxe_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"taxe d'apprentissage {taxe_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-05-06 01:33:50 +02:00
|
|
|
)
|
|
|
|
form = TaxeApprentissageModificationForm(annee=taxe.annee)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-05-06 01:33:50 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
taxe.montant = form.montant.data
|
|
|
|
taxe.notes = form.notes.data.strip()
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=taxe.entreprise_id,
|
|
|
|
object="taxe apprentissage",
|
|
|
|
object_id=taxe.id,
|
|
|
|
text=f"Modification d'une taxe d'apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-05-06 01:33:50 +02:00
|
|
|
db.session.commit()
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=taxe.entreprise_id)
|
|
|
|
)
|
2022-05-06 01:33:50 +02:00
|
|
|
elif request.method == "GET":
|
|
|
|
form.montant.data = taxe.montant
|
|
|
|
form.notes.data = taxe.notes
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-05-06 01:33:50 +02:00
|
|
|
title="Modification taxe apprentissage",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/delete_taxe_apprentissage/<int:taxe_id>",
|
2022-05-06 01:33:50 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-07-11 16:06:38 +02:00
|
|
|
def delete_taxe_apprentissage(entreprise_id, taxe_id):
|
2022-05-06 01:33:50 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
Permet de modifier une taxe d'apprentissage sur une fiche entreprise
|
2022-05-06 01:33:50 +02:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
taxe = EntrepriseTaxeApprentissage.query.filter_by(
|
|
|
|
id=taxe_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"taxe d'apprentissage {taxe_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-05-06 01:33:50 +02:00
|
|
|
)
|
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-05-06 01:33:50 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(taxe)
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=taxe.entreprise_id,
|
|
|
|
object="taxe apprentissage",
|
|
|
|
object_id=taxe.id,
|
|
|
|
text=f"Suppression d'une taxe d'apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-05-06 01:33:50 +02:00
|
|
|
db.session.commit()
|
2023-06-01 18:25:54 +02:00
|
|
|
flash("La taxe d'apprentissage a été supprimée de la liste.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=taxe.entreprise_id)
|
|
|
|
)
|
2022-05-06 01:33:50 +02:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-05-06 01:33:50 +02:00
|
|
|
title="Supprimer taxe apprentissage",
|
|
|
|
form=form,
|
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/add_offre", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_offre(entreprise_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter une offre a une entreprise
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
|
|
|
form = OffreCreationForm(hidden_entreprise_id=entreprise.id)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
offre = EntrepriseOffre(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
intitule=form.intitule.data.strip(),
|
|
|
|
description=form.description.data.strip(),
|
|
|
|
type_offre=form.type_offre.data.strip(),
|
|
|
|
missions=form.missions.data.strip(),
|
2021-12-28 21:20:50 +01:00
|
|
|
duree=form.duree.data.strip(),
|
2022-01-24 18:07:54 +01:00
|
|
|
expiration_date=form.expiration_date.data,
|
2022-06-02 21:49:37 +02:00
|
|
|
correspondant_id=form.correspondant.data
|
|
|
|
if form.correspondant.data != ""
|
|
|
|
else None,
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-02-03 18:07:16 +01:00
|
|
|
db.session.add(offre)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(offre)
|
|
|
|
for dept in form.depts.data:
|
|
|
|
offre_dept = EntrepriseOffreDepartement(
|
|
|
|
offre_id=offre.id,
|
|
|
|
dept_id=dept,
|
|
|
|
)
|
|
|
|
db.session.add(offre_dept)
|
2022-04-12 19:44:09 +02:00
|
|
|
if form.fichier.data:
|
|
|
|
date = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
f"{date}",
|
|
|
|
)
|
|
|
|
os.makedirs(path)
|
|
|
|
file = form.fichier.data
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
file.save(os.path.join(path, filename))
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-05-06 18:50:12 +02:00
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
object="offre",
|
|
|
|
object_id=offre.id,
|
2021-12-28 21:20:50 +01:00
|
|
|
text="Création d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'offre a été ajouté à la fiche entreprise.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Ajout offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/edit_offre/<int:offre_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_offre(entreprise_id, offre_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de modifier une offre
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-02-04 17:12:56 +01:00
|
|
|
offre_depts = EntrepriseOffreDepartement.query.filter_by(offre_id=offre.id).all()
|
2022-08-23 18:54:44 +02:00
|
|
|
offre_depts_list = [(offre_dept.dept_id) for offre_dept in offre_depts]
|
2022-03-04 17:10:07 +01:00
|
|
|
form = OffreModificationForm(
|
2022-03-28 23:44:57 +02:00
|
|
|
hidden_entreprise_id=offre.entreprise_id, correspondant=offre.correspondant_id
|
2022-03-04 17:10:07 +01:00
|
|
|
)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
offre.intitule = form.intitule.data.strip()
|
|
|
|
offre.description = form.description.data.strip()
|
|
|
|
offre.type_offre = form.type_offre.data.strip()
|
|
|
|
offre.missions = form.missions.data.strip()
|
|
|
|
offre.duree = form.duree.data.strip()
|
2022-01-24 18:07:54 +01:00
|
|
|
offre.expiration_date = form.expiration_date.data
|
2022-06-02 21:49:37 +02:00
|
|
|
if form.correspondant.data == "":
|
|
|
|
offre.correspondant_id = sql.null()
|
|
|
|
else:
|
|
|
|
offre.correspondant_id = form.correspondant.data
|
2022-02-04 17:12:56 +01:00
|
|
|
if offre_depts_list != form.depts.data:
|
|
|
|
for dept in form.depts.data:
|
|
|
|
if dept not in offre_depts_list:
|
|
|
|
offre_dept = EntrepriseOffreDepartement(
|
|
|
|
offre_id=offre.id,
|
|
|
|
dept_id=dept,
|
|
|
|
)
|
|
|
|
db.session.add(offre_dept)
|
|
|
|
for dept in offre_depts_list:
|
|
|
|
if dept not in form.depts.data:
|
|
|
|
offre_dept = EntrepriseOffreDepartement.query.filter_by(
|
|
|
|
offre_id=offre.id, dept_id=dept
|
|
|
|
).first_or_404()
|
|
|
|
db.session.delete(offre_dept)
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-05-06 18:50:12 +02:00
|
|
|
entreprise_id=offre.entreprise_id,
|
|
|
|
object="offre",
|
|
|
|
object_id=offre.id,
|
2021-12-28 21:20:50 +01:00
|
|
|
text="Modification d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("L'offre a été modifié.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
elif request.method == "GET":
|
2021-12-23 19:28:25 +01:00
|
|
|
form.intitule.data = offre.intitule
|
|
|
|
form.description.data = offre.description
|
|
|
|
form.type_offre.data = offre.type_offre
|
|
|
|
form.missions.data = offre.missions
|
|
|
|
form.duree.data = offre.duree
|
2022-01-24 18:07:54 +01:00
|
|
|
form.expiration_date.data = offre.expiration_date
|
2022-02-04 17:12:56 +01:00
|
|
|
form.depts.data = offre_depts_list
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Modification offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/delete_offre/<int:offre_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def delete_offre(entreprise_id, offre_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de supprimer une offre
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
entreprise_id = offre.entreprise.id
|
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(offre)
|
2022-02-08 16:40:32 +01:00
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-05-06 18:50:12 +02:00
|
|
|
entreprise_id=offre.entreprise_id,
|
|
|
|
object="offre",
|
|
|
|
object_id=offre.id,
|
2021-12-28 21:20:50 +01:00
|
|
|
text="Suppression d'une offre",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2023-06-01 18:25:54 +02:00
|
|
|
flash("L'offre a été supprimée de la fiche entreprise.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Supression offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/expired/<int:offre_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def expired(entreprise_id, offre_id):
|
2022-03-02 15:27:35 +01:00
|
|
|
"""
|
|
|
|
Permet de rendre expirée et non expirée une offre
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-03-01 18:45:04 +01:00
|
|
|
)
|
|
|
|
offre.expired = not offre.expired
|
|
|
|
db.session.commit()
|
2022-03-02 15:27:35 +01:00
|
|
|
if offre.expired:
|
|
|
|
flash("L'offre a été rendu expirée")
|
|
|
|
else:
|
|
|
|
flash("L'offre a été rendu non expirée")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id)
|
|
|
|
)
|
2022-03-01 18:45:04 +01:00
|
|
|
|
|
|
|
|
2022-04-25 20:49:21 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/add_site",
|
2022-04-25 20:49:21 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_site(entreprise_id):
|
2022-08-10 02:27:52 +02:00
|
|
|
"""
|
|
|
|
Permet d'ajouter un site a une entreprise
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
|
|
|
form = SiteCreationForm(hidden_entreprise_id=entreprise.id)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-04-25 20:49:21 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
site = EntrepriseSite(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
nom=form.nom.data.strip(),
|
|
|
|
adresse=form.adresse.data.strip(),
|
|
|
|
codepostal=form.codepostal.data.strip(),
|
|
|
|
ville=form.ville.data.strip(),
|
|
|
|
pays=form.pays.data.strip() if form.pays.data.strip() else "FRANCE",
|
|
|
|
)
|
|
|
|
db.session.add(site)
|
|
|
|
db.session.commit()
|
2022-07-08 18:56:27 +02:00
|
|
|
db.session.refresh(site)
|
2022-07-20 18:24:15 +02:00
|
|
|
lien_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom} - {form.nom.data.strip()}</a>"
|
2022-07-08 18:56:27 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
object="site",
|
|
|
|
object_id=site.id,
|
|
|
|
text=f"{lien_entreprise} - Création d'un site",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2022-04-25 20:49:21 +02:00
|
|
|
flash("Le site a été créé et ajouté à la fiche entreprise")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2022-04-25 20:49:21 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-04-25 20:49:21 +02:00
|
|
|
title="Ajout site",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-28 23:04:31 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/edit_site/<int:site_id>",
|
2022-04-28 23:04:31 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_site(entreprise_id, site_id):
|
2022-08-10 02:27:52 +02:00
|
|
|
"""
|
|
|
|
Permet de modifier une offre
|
|
|
|
"""
|
2022-04-28 23:04:31 +02:00
|
|
|
site = EntrepriseSite.query.filter_by(
|
2022-07-11 16:06:38 +02:00
|
|
|
id=site_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"site {site_id} inconnu pour l'entreprise {entreprise_id}"
|
|
|
|
)
|
2022-04-28 23:04:31 +02:00
|
|
|
form = SiteModificationForm(
|
2022-07-11 16:06:38 +02:00
|
|
|
hidden_entreprise_id=site.entreprise_id, hidden_site_id=site.id
|
2022-04-28 23:04:31 +02:00
|
|
|
)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-04-28 23:04:31 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
site.nom = form.nom.data.strip()
|
|
|
|
site.adresse = form.adresse.data.strip()
|
|
|
|
site.codepostal = form.codepostal.data.strip()
|
|
|
|
site.ville = form.ville.data.strip()
|
|
|
|
site.pays = (form.pays.data.strip() if form.pays.data.strip() else "FRANCE",)
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=site.entreprise_id,
|
|
|
|
object="site",
|
|
|
|
object_id=site.id,
|
|
|
|
text="Modification d'un site",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-04-28 23:04:31 +02:00
|
|
|
db.session.commit()
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=site.entreprise_id)
|
|
|
|
)
|
2022-04-28 23:04:31 +02:00
|
|
|
elif request.method == "GET":
|
|
|
|
form.nom.data = site.nom
|
|
|
|
form.adresse.data = site.adresse
|
|
|
|
form.codepostal.data = site.codepostal
|
|
|
|
form.ville.data = site.ville
|
|
|
|
form.pays.data = site.pays
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-04-28 23:04:31 +02:00
|
|
|
title="Modification site",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-25 20:49:21 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/site/<int:site_id>/add_correspondant",
|
2022-04-25 20:49:21 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_correspondant(entreprise_id, site_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet d'ajouter un correspondant a une entreprise
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
site = EntrepriseSite.query.filter_by(
|
|
|
|
id=site_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"site {site_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-07-11 20:17:34 +02:00
|
|
|
form = CorrespondantsCreationForm(hidden_site_id=site.id)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-07 02:54:11 +02:00
|
|
|
for correspondant_entry in form.correspondants.entries:
|
|
|
|
correspondant = EntrepriseCorrespondant(
|
2022-04-25 20:49:21 +02:00
|
|
|
site_id=site.id,
|
2022-04-20 22:37:04 +02:00
|
|
|
civilite=correspondant_entry.civilite.data,
|
2022-04-07 02:54:11 +02:00
|
|
|
nom=correspondant_entry.nom.data.strip(),
|
|
|
|
prenom=correspondant_entry.prenom.data.strip(),
|
|
|
|
telephone=correspondant_entry.telephone.data.strip(),
|
|
|
|
mail=correspondant_entry.mail.data.strip(),
|
|
|
|
poste=correspondant_entry.poste.data.strip(),
|
|
|
|
service=correspondant_entry.service.data.strip(),
|
2022-04-20 22:37:04 +02:00
|
|
|
origine=correspondant_entry.origine.data.strip(),
|
|
|
|
notes=correspondant_entry.notes.data.strip(),
|
2022-04-07 02:54:11 +02:00
|
|
|
)
|
2022-05-06 18:50:12 +02:00
|
|
|
db.session.add(correspondant)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(correspondant)
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2022-04-07 02:54:11 +02:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-07-11 20:17:34 +02:00
|
|
|
entreprise_id=correspondant.site.entreprise.id,
|
2022-05-06 18:50:12 +02:00
|
|
|
object="correspondant",
|
|
|
|
object_id=correspondant.id,
|
2022-04-07 02:54:11 +02:00
|
|
|
text="Création d'un correspondant",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("Le correspondant a été ajouté à la fiche entreprise.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=site.entreprise_id)
|
|
|
|
)
|
2022-02-08 16:40:32 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_ajout_correspondants.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Ajout correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/site/<int:site_id>/edit_correspondant/<int:correspondant_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_correspondant(entreprise_id, site_id, correspondant_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet de modifier un correspondant
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-05-31 19:15:24 +02:00
|
|
|
correspondant = (
|
|
|
|
db.session.query(EntrepriseCorrespondant)
|
2022-07-11 20:17:34 +02:00
|
|
|
.join(
|
|
|
|
EntrepriseSite,
|
|
|
|
EntrepriseCorrespondant.site_id == EntrepriseSite.id,
|
|
|
|
)
|
|
|
|
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
|
2022-07-11 16:06:38 +02:00
|
|
|
.filter(
|
2022-07-11 20:17:34 +02:00
|
|
|
EntrepriseCorrespondant.id == correspondant_id,
|
|
|
|
EntrepriseCorrespondant.site_id == site_id,
|
|
|
|
EntrepriseSite.entreprise_id == entreprise_id,
|
|
|
|
Entreprise.visible == True,
|
|
|
|
)
|
|
|
|
.first_or_404(
|
|
|
|
description=f"correspondant {correspondant_id} inconnu pour l'entreprise {entreprise_id} et le site {site_id}"
|
2022-07-11 16:06:38 +02:00
|
|
|
)
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
form = CorrespondantModificationForm(
|
2022-07-11 20:17:34 +02:00
|
|
|
hidden_site_id=correspondant.site.id,
|
2022-03-28 23:44:57 +02:00
|
|
|
hidden_correspondant_id=correspondant.id,
|
2022-08-24 21:06:11 +02:00
|
|
|
hidden_entreprise_id=entreprise_id,
|
|
|
|
site=correspondant.site_id,
|
2022-02-07 21:40:58 +01:00
|
|
|
)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-20 22:37:04 +02:00
|
|
|
correspondant.civilite = form.civilite.data
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant.nom = form.nom.data.strip()
|
|
|
|
correspondant.prenom = form.prenom.data.strip()
|
|
|
|
correspondant.telephone = form.telephone.data.strip()
|
|
|
|
correspondant.mail = form.mail.data.strip()
|
|
|
|
correspondant.poste = form.poste.data.strip()
|
|
|
|
correspondant.service = form.service.data.strip()
|
2022-04-20 22:37:04 +02:00
|
|
|
correspondant.origine = form.origine.data.strip()
|
|
|
|
correspondant.notes = form.notes.data.strip()
|
2022-08-24 21:06:11 +02:00
|
|
|
correspondant.site_id = form.site.data
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2021-12-28 21:20:50 +01:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-07-11 20:17:34 +02:00
|
|
|
entreprise_id=correspondant.site.entreprise.id,
|
2022-05-06 18:50:12 +02:00
|
|
|
object="correspondant",
|
|
|
|
object_id=correspondant.id,
|
2022-03-28 23:44:57 +02:00
|
|
|
text="Modification d'un correspondant",
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2022-03-28 23:44:57 +02:00
|
|
|
flash("Le correspondant a été modifié.")
|
2021-12-28 21:20:50 +01:00
|
|
|
return redirect(
|
2022-07-11 16:06:38 +02:00
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise",
|
2022-07-11 20:17:34 +02:00
|
|
|
entreprise_id=correspondant.site.entreprise.id,
|
2022-07-11 16:06:38 +02:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
elif request.method == "GET":
|
2022-04-20 22:37:04 +02:00
|
|
|
form.civilite.data = correspondant.civilite
|
2022-03-28 23:44:57 +02:00
|
|
|
form.nom.data = correspondant.nom
|
|
|
|
form.prenom.data = correspondant.prenom
|
|
|
|
form.telephone.data = correspondant.telephone
|
|
|
|
form.mail.data = correspondant.mail
|
|
|
|
form.poste.data = correspondant.poste
|
|
|
|
form.service.data = correspondant.service
|
2022-04-20 22:37:04 +02:00
|
|
|
form.origine.data = correspondant.origine
|
|
|
|
form.notes.data = correspondant.notes
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Modification correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/site/<int:site_id>/delete_correspondant/<int:correspondant_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def delete_correspondant(entreprise_id, site_id, correspondant_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
Permet de supprimer un correspondant
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-05-31 19:15:24 +02:00
|
|
|
correspondant = (
|
|
|
|
db.session.query(EntrepriseCorrespondant)
|
2022-07-11 20:17:34 +02:00
|
|
|
.join(
|
|
|
|
EntrepriseSite,
|
|
|
|
EntrepriseCorrespondant.site_id == EntrepriseSite.id,
|
|
|
|
)
|
|
|
|
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
|
2022-07-11 16:06:38 +02:00
|
|
|
.filter(
|
2022-07-11 20:17:34 +02:00
|
|
|
EntrepriseCorrespondant.id == correspondant_id,
|
|
|
|
EntrepriseCorrespondant.site_id == site_id,
|
|
|
|
EntrepriseSite.entreprise_id == entreprise_id,
|
|
|
|
Entreprise.visible == True,
|
|
|
|
)
|
|
|
|
.first_or_404(
|
|
|
|
description=f"correspondant {correspondant_id} inconnu pour l'entreprise {entreprise_id} et le site {site_id}"
|
2022-07-11 16:06:38 +02:00
|
|
|
)
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-12 00:21:25 +02:00
|
|
|
db.session.delete(correspondant)
|
2022-07-04 21:12:56 +02:00
|
|
|
log = EntrepriseHistorique(
|
2022-04-12 00:21:25 +02:00
|
|
|
authenticated_user=current_user.user_name,
|
2022-07-11 20:17:34 +02:00
|
|
|
entreprise_id=correspondant.site.entreprise.id,
|
2022-05-06 18:50:12 +02:00
|
|
|
object="correspondant",
|
|
|
|
object_id=correspondant.id,
|
2022-04-12 00:21:25 +02:00
|
|
|
text="Suppression d'un correspondant",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
flash("Le correspondant a été supprimé de la fiche entreprise.")
|
|
|
|
return redirect(
|
2022-07-11 16:06:38 +02:00
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise",
|
2022-07-11 20:17:34 +02:00
|
|
|
entreprise_id=correspondant.site.entreprise.id,
|
2022-07-11 16:06:38 +02:00
|
|
|
)
|
2022-04-12 00:21:25 +02:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Supression correspondant",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-08-23 18:54:44 +02:00
|
|
|
@bp.route("/fiche_entreprise/<int:entreprise_id>/contacts")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2022-08-23 18:54:44 +02:00
|
|
|
def contacts(entreprise_id):
|
|
|
|
"""
|
|
|
|
Permet d'afficher une page avec la liste des contacts d'une entreprise
|
|
|
|
"""
|
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
|
|
|
contacts = EntrepriseContact.query.filter_by(entreprise=entreprise.id).all()
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/contacts.j2",
|
2022-08-23 18:54:44 +02:00
|
|
|
title="Liste des contacts",
|
|
|
|
contacts=contacts,
|
|
|
|
entreprise=entreprise,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/contacts/add_contact",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_contact(entreprise_id):
|
2022-04-05 02:26:43 +02:00
|
|
|
"""
|
|
|
|
Permet d'ajouter un contact avec une entreprise
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
2022-04-15 18:16:48 +02:00
|
|
|
form = ContactCreationForm(
|
|
|
|
date=f"{datetime.now().strftime('%Y-%m-%dT%H:%M')}",
|
|
|
|
utilisateur=f"{current_user.nom} {current_user.prenom} ({current_user.user_name})"
|
|
|
|
if current_user.nom and current_user.prenom
|
|
|
|
else "",
|
|
|
|
)
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(url_for("entreprises.contacts", entreprise_id=entreprise_id))
|
2022-04-05 02:26:43 +02:00
|
|
|
if form.validate_on_submit():
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur_data = form.utilisateur.data.upper().strip()
|
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
|
|
|
)
|
|
|
|
utilisateur = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(utilisateur_data=utilisateur_data)
|
|
|
|
.first()
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
contact = EntrepriseContact(
|
|
|
|
date=form.date.data,
|
2022-04-15 18:16:48 +02:00
|
|
|
user=utilisateur.id,
|
2022-04-05 02:26:43 +02:00
|
|
|
entreprise=entreprise.id,
|
|
|
|
notes=form.notes.data.strip(),
|
|
|
|
)
|
|
|
|
db.session.add(contact)
|
|
|
|
db.session.commit()
|
2022-07-20 18:24:15 +02:00
|
|
|
db.session.refresh(contact)
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=contact.entreprise,
|
|
|
|
object="contact",
|
|
|
|
object_id=contact.id,
|
|
|
|
text="Création d'un contact",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(url_for("entreprises.contacts", entreprise_id=entreprise.id))
|
2022-04-05 02:26:43 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-04-05 02:26:43 +02:00
|
|
|
title="Ajout contact",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/contacts/edit_contact/<int:contact_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_contact(entreprise_id, contact_id):
|
2022-04-05 02:26:43 +02:00
|
|
|
"""
|
|
|
|
Permet d'editer un contact avec une entreprise
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
contact = EntrepriseContact.query.filter_by(
|
|
|
|
id=contact_id, entreprise=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"contact {contact_id} inconnu pour l'entreprise {entreprise_id}"
|
2022-04-05 02:26:43 +02:00
|
|
|
)
|
|
|
|
form = ContactModificationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(url_for("entreprises.contacts", entreprise_id=entreprise_id))
|
2022-04-05 02:26:43 +02:00
|
|
|
if form.validate_on_submit():
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur_data = form.utilisateur.data.upper().strip()
|
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
|
|
|
)
|
|
|
|
utilisateur = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(utilisateur_data=utilisateur_data)
|
|
|
|
.first()
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
contact.date = form.date.data
|
2022-04-15 18:16:48 +02:00
|
|
|
contact.user = utilisateur.id
|
2022-04-05 02:26:43 +02:00
|
|
|
contact.notes = form.notes.data
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=contact.entreprise,
|
|
|
|
object="contact",
|
|
|
|
object_id=contact.id,
|
|
|
|
text="Modification d'un contact",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-04-05 02:26:43 +02:00
|
|
|
db.session.commit()
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.contacts", entreprise_id=contact.entreprise)
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
elif request.method == "GET":
|
2022-04-15 18:16:48 +02:00
|
|
|
utilisateur = User.query.filter_by(id=contact.user).first()
|
|
|
|
form.date.data = contact.date.strftime("%Y-%m-%dT%H:%M")
|
|
|
|
form.utilisateur.data = (
|
|
|
|
f"{utilisateur.nom} {utilisateur.prenom} ({utilisateur.user_name})"
|
|
|
|
)
|
2022-04-05 02:26:43 +02:00
|
|
|
form.notes.data = contact.notes
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-04-05 02:26:43 +02:00
|
|
|
title="Modification contact",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-20 18:24:15 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/contacts/delete_contact/<int:contact_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-20 18:24:15 +02:00
|
|
|
def delete_contact(entreprise_id, contact_id):
|
|
|
|
"""
|
|
|
|
Permet de supprimer un contact
|
|
|
|
"""
|
|
|
|
contact = EntrepriseContact.query.filter_by(
|
|
|
|
id=contact_id, entreprise=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"contact {contact_id} inconnu pour l'entreprise {entreprise_id}"
|
|
|
|
)
|
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(url_for("entreprises.contacts", entreprise_id=entreprise_id))
|
2022-07-20 18:24:15 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(contact)
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=contact.entreprise,
|
|
|
|
object="contact",
|
|
|
|
object_id=contact.id,
|
|
|
|
text="Suppression d'un contact",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.contacts", entreprise_id=contact.entreprise)
|
|
|
|
)
|
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-07-20 18:24:15 +02:00
|
|
|
title="Supression contact",
|
|
|
|
form=form,
|
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/add_stage_apprentissage",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_stage_apprentissage(entreprise_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2023-06-01 17:58:30 +02:00
|
|
|
Permet d'ajouter un étudiant ayant réalisé un stage ou alternance
|
|
|
|
sur la fiche de l'entreprise
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(
|
|
|
|
id=entreprise_id, visible=True
|
|
|
|
).first_or_404(description=f"entreprise {entreprise_id} inconnue")
|
2022-03-28 23:44:57 +02:00
|
|
|
form = StageApprentissageCreationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
if form.validate_on_submit():
|
2023-06-01 17:58:30 +02:00
|
|
|
etudid = form.etudid.data
|
|
|
|
etudiant = Identite.query.get_or_404(etudid)
|
2021-12-28 21:20:50 +01:00
|
|
|
formation = etudiant.inscription_courante_date(
|
|
|
|
form.date_debut.data, form.date_fin.data
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage(
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
etudid=etudiant.id,
|
|
|
|
type_offre=form.type_offre.data.strip(),
|
|
|
|
date_debut=form.date_debut.data,
|
|
|
|
date_fin=form.date_fin.data,
|
|
|
|
formation_text=formation.formsemestre.titre if formation else None,
|
|
|
|
formation_scodoc=formation.formsemestre.formsemestre_id
|
|
|
|
if formation
|
|
|
|
else None,
|
2022-03-29 19:07:59 +02:00
|
|
|
notes=form.notes.data.strip(),
|
2021-12-23 19:28:25 +01:00
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
db.session.add(stage_apprentissage)
|
2021-12-23 19:28:25 +01:00
|
|
|
db.session.commit()
|
2022-07-20 18:24:15 +02:00
|
|
|
db.session.refresh(stage_apprentissage)
|
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=stage_apprentissage.entreprise_id,
|
|
|
|
object="stage apprentissage",
|
|
|
|
object_id=stage_apprentissage.id,
|
|
|
|
text="Création d'un stage/apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
|
|
|
db.session.commit()
|
2021-12-23 19:28:25 +01:00
|
|
|
flash("L'étudiant a été ajouté sur la fiche entreprise.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise.id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_ajout_stage_apprentissage.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Ajout stage / apprentissage",
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/edit_stage_apprentissage/<int:stage_apprentissage_id>",
|
|
|
|
methods=["GET", "POST"],
|
2022-04-13 20:59:26 +02:00
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def edit_stage_apprentissage(entreprise_id, stage_apprentissage_id):
|
2022-03-30 20:17:35 +02:00
|
|
|
"""
|
2023-06-01 17:58:30 +02:00
|
|
|
Permet de modifier un étudiant ayant réalisé un stage ou alternance sur la fiche de l'entreprise
|
2022-03-30 20:17:35 +02:00
|
|
|
"""
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage.query.filter_by(
|
2022-07-11 16:06:38 +02:00
|
|
|
id=stage_apprentissage_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"stage_apprentissage {stage_apprentissage_id} inconnue pour l'entreprise {entreprise_id}"
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
etudiant = Identite.query.filter_by(id=stage_apprentissage.etudid).first_or_404(
|
2022-07-11 16:06:38 +02:00
|
|
|
description=f"etudiant {stage_apprentissage.etudid} inconnue"
|
2022-03-28 23:44:57 +02:00
|
|
|
)
|
2023-06-01 17:58:30 +02:00
|
|
|
form = StageApprentissageCreationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-03-28 23:44:57 +02:00
|
|
|
if form.validate_on_submit():
|
2023-06-01 17:58:30 +02:00
|
|
|
etudid = form.etudid.data
|
|
|
|
etudiant = Identite.query.get_or_404(etudid)
|
2022-03-28 23:44:57 +02:00
|
|
|
formation = etudiant.inscription_courante_date(
|
|
|
|
form.date_debut.data, form.date_fin.data
|
|
|
|
)
|
|
|
|
stage_apprentissage.etudid = etudiant.id
|
|
|
|
stage_apprentissage.type_offre = form.type_offre.data.strip()
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage.date_debut = form.date_debut.data
|
|
|
|
stage_apprentissage.date_fin = form.date_fin.data
|
2022-03-28 23:44:57 +02:00
|
|
|
stage_apprentissage.formation_text = (
|
|
|
|
formation.formsemestre.titre if formation else None,
|
|
|
|
)
|
|
|
|
stage_apprentissage.formation_scodoc = (
|
|
|
|
formation.formsemestre.formsemestre_id if formation else None,
|
|
|
|
)
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage.notes = form.notes.data.strip()
|
2023-06-01 17:58:30 +02:00
|
|
|
db.session.add(stage_apprentissage)
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=stage_apprentissage.entreprise_id,
|
|
|
|
object="stage apprentissage",
|
|
|
|
object_id=stage_apprentissage.id,
|
|
|
|
text="Modification d'un stage/apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-03-28 23:44:57 +02:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
2022-07-11 16:06:38 +02:00
|
|
|
"entreprises.fiche_entreprise",
|
|
|
|
entreprise_id=stage_apprentissage.entreprise_id,
|
2022-03-28 23:44:57 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
elif request.method == "GET":
|
2023-11-22 23:31:16 +01:00
|
|
|
form.etudiant.data = f"""{scu.format_nom(etudiant.nom)} {
|
|
|
|
scu.format_prenom(etudiant.prenom)}"""
|
2023-06-01 17:58:30 +02:00
|
|
|
form.etudid.data = etudiant.id
|
2022-03-28 23:44:57 +02:00
|
|
|
form.type_offre.data = stage_apprentissage.type_offre
|
|
|
|
form.date_debut.data = stage_apprentissage.date_debut
|
|
|
|
form.date_fin.data = stage_apprentissage.date_fin
|
2022-03-29 19:07:59 +02:00
|
|
|
form.notes.data = stage_apprentissage.notes
|
2022-03-28 23:44:57 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_ajout_stage_apprentissage.j2",
|
2022-03-28 23:44:57 +02:00
|
|
|
title="Modification stage / apprentissage",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/delete_stage_apprentissage/<int:stage_apprentissage_id>",
|
|
|
|
methods=["GET", "POST"],
|
2022-04-13 20:59:26 +02:00
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def delete_stage_apprentissage(entreprise_id, stage_apprentissage_id):
|
2022-03-30 20:17:35 +02:00
|
|
|
"""
|
|
|
|
Permet de supprimer un étudiant ayant réalisé un stage ou une alternance sur la fiche entreprise de l'entreprise
|
|
|
|
"""
|
2022-03-29 19:07:59 +02:00
|
|
|
stage_apprentissage = EntrepriseStageApprentissage.query.filter_by(
|
2022-07-11 16:06:38 +02:00
|
|
|
id=stage_apprentissage_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(description=f"stage_apprentissage {stage_apprentissage_id} inconnu")
|
2022-03-29 19:07:59 +02:00
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2022-03-29 19:07:59 +02:00
|
|
|
if form.validate_on_submit():
|
|
|
|
db.session.delete(stage_apprentissage)
|
2022-07-20 18:24:15 +02:00
|
|
|
log = EntrepriseHistorique(
|
|
|
|
authenticated_user=current_user.user_name,
|
|
|
|
entreprise_id=stage_apprentissage.entreprise_id,
|
|
|
|
object="stage apprentissage",
|
|
|
|
object_id=stage_apprentissage.id,
|
|
|
|
text="Suppression d'un stage/apprentissage",
|
|
|
|
)
|
|
|
|
db.session.add(log)
|
2022-03-29 19:07:59 +02:00
|
|
|
db.session.commit()
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
2022-07-11 16:06:38 +02:00
|
|
|
"entreprises.fiche_entreprise",
|
|
|
|
entreprise_id=stage_apprentissage.entreprise_id,
|
2022-03-29 19:07:59 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-03-29 19:07:59 +02:00
|
|
|
title="Supression stage/apprentissage",
|
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2022-03-29 19:07:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/envoyer_offre/<int:offre_id>",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepSend)
|
2022-07-11 16:06:38 +02:00
|
|
|
def envoyer_offre(entreprise_id, offre_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet d'envoyer une offre à un utilisateur ScoDoc
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-23 23:21:47 +01:00
|
|
|
form = EnvoiOffreForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-23 23:21:47 +01:00
|
|
|
if form.validate_on_submit():
|
2022-04-05 23:01:38 +02:00
|
|
|
for responsable in form.responsables.entries:
|
|
|
|
if responsable.data.strip():
|
|
|
|
responsable_data = responsable.data.upper().strip()
|
2022-03-30 20:17:35 +02:00
|
|
|
stm = text(
|
|
|
|
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:responsable_data"
|
|
|
|
)
|
|
|
|
responsable = (
|
|
|
|
User.query.from_statement(stm)
|
|
|
|
.params(responsable_data=responsable_data)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
envoi_offre = EntrepriseEnvoiOffre(
|
|
|
|
sender_id=current_user.id,
|
|
|
|
receiver_id=responsable.id,
|
|
|
|
offre_id=offre.id,
|
|
|
|
)
|
|
|
|
db.session.add(envoi_offre)
|
2022-04-07 02:54:11 +02:00
|
|
|
db.session.commit()
|
2022-03-30 20:17:35 +02:00
|
|
|
flash(f"L'offre a été envoyé à {responsable.get_nomplogin()}.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form_envoi_offre.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Envoyer une offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
2021-12-23 23:21:47 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/etudiants")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2023-04-06 16:10:32 +02:00
|
|
|
@as_json
|
2021-12-23 19:28:25 +01:00
|
|
|
def json_etudiants():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de récuperer un JSON avec tous les étudiants
|
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
if request.args.get("term") is None:
|
2021-12-30 19:37:46 +01:00
|
|
|
abort(400)
|
2021-12-28 21:20:50 +01:00
|
|
|
term = request.args.get("term").strip()
|
2022-05-04 18:59:29 +02:00
|
|
|
etudiants = Identite.query.filter(Identite.nom.ilike(f"%{term}%")).limit(30).all()
|
2021-12-23 19:28:25 +01:00
|
|
|
list = []
|
|
|
|
for etudiant in etudiants:
|
2022-02-10 21:17:22 +01:00
|
|
|
content = {}
|
2023-11-22 23:31:16 +01:00
|
|
|
value = f"{scu.format_nom(etudiant.nom)} {scu.format_prenom(etudiant.prenom)}"
|
2021-12-23 19:28:25 +01:00
|
|
|
if etudiant.inscription_courante() is not None:
|
|
|
|
content = {
|
|
|
|
"id": f"{etudiant.id}",
|
|
|
|
"value": value,
|
2022-05-30 18:12:26 +02:00
|
|
|
"info": f"Département {are.get_dept_acronym_by_id(etudiant.dept_id)} - {etudiant.inscription_courante().formsemestre.titre}",
|
2021-12-23 19:28:25 +01:00
|
|
|
}
|
|
|
|
else:
|
2022-05-30 18:12:26 +02:00
|
|
|
content = {
|
|
|
|
"id": f"{etudiant.id}",
|
|
|
|
"value": value,
|
|
|
|
"info": f"Département {are.get_dept_acronym_by_id(etudiant.dept_id)}",
|
|
|
|
}
|
2021-12-23 19:28:25 +01:00
|
|
|
list.append(content)
|
2023-04-06 16:10:32 +02:00
|
|
|
return list
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
@bp.route("/responsables")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2021-12-23 19:28:25 +01:00
|
|
|
def json_responsables():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet de récuperer un JSON avec tous les utilisateurs ScoDoc
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
2022-02-21 20:22:27 +01:00
|
|
|
if request.args.get("term") is None:
|
2021-12-30 19:37:46 +01:00
|
|
|
abort(400)
|
2021-12-28 21:20:50 +01:00
|
|
|
term = request.args.get("term").strip()
|
2022-05-04 18:59:29 +02:00
|
|
|
responsables = (
|
|
|
|
User.query.filter(
|
|
|
|
User.nom.ilike(f"%{term}%"), User.nom.is_not(None), User.prenom.is_not(None)
|
|
|
|
)
|
|
|
|
.limit(30)
|
|
|
|
.all()
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
list = []
|
2022-02-10 21:17:22 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
for responsable in responsables:
|
2022-02-10 21:17:22 +01:00
|
|
|
content = {}
|
2021-12-23 19:28:25 +01:00
|
|
|
value = f"{responsable.get_nomplogin()}"
|
2022-05-30 18:12:26 +02:00
|
|
|
content = {"id": f"{responsable.id}", "value": value}
|
2021-12-23 19:28:25 +01:00
|
|
|
list.append(content)
|
2023-04-06 16:10:32 +02:00
|
|
|
return list
|
2021-12-24 18:10:19 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-06-01 21:17:15 +02:00
|
|
|
@bp.route("/export_donnees")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepExport)
|
2022-06-01 21:17:15 +02:00
|
|
|
def export_donnees():
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'exporter la liste des entreprises sous format excel (.xlsx)
|
|
|
|
"""
|
2022-05-31 19:15:24 +02:00
|
|
|
entreprise = Entreprise.query.filter_by(visible=True).first()
|
|
|
|
if entreprise:
|
|
|
|
wb = are.get_excel_book_are(export=True)
|
|
|
|
xlsx = wb.generate()
|
2022-06-01 21:17:15 +02:00
|
|
|
filename = "ExportApplicationRelationsEntreprises"
|
2021-12-27 11:48:58 +01:00
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
|
|
|
else:
|
2022-04-12 00:21:25 +02:00
|
|
|
return redirect(url_for("entreprises.index"))
|
2021-12-27 11:48:58 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-06-01 21:17:15 +02:00
|
|
|
@bp.route("/import_donnees/get_file_sample")
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepExport)
|
2022-08-23 18:54:44 +02:00
|
|
|
def import_donnees_get_file_sample():
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
2022-03-02 15:27:35 +01:00
|
|
|
Permet de récupérer un fichier exemple vide pour pouvoir importer des entreprises
|
2022-02-10 21:17:22 +01:00
|
|
|
"""
|
2022-05-31 19:15:24 +02:00
|
|
|
wb = are.get_excel_book_are()
|
2022-05-30 18:12:26 +02:00
|
|
|
xlsx = wb.generate()
|
2022-06-01 21:17:15 +02:00
|
|
|
filename = "ImportApplicationRelationsEntreprises"
|
2022-02-07 18:39:32 +01:00
|
|
|
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
|
|
|
|
|
|
|
|
2022-06-01 21:17:15 +02:00
|
|
|
@bp.route("/import_donnees", methods=["GET", "POST"])
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepExport)
|
2022-06-01 21:17:15 +02:00
|
|
|
def import_donnees():
|
2022-02-08 16:40:32 +01:00
|
|
|
"""
|
2022-07-07 11:56:18 +02:00
|
|
|
Permet d'importer des entreprises à partir d'un fichier excel (.xlsx)
|
2022-02-08 16:40:32 +01:00
|
|
|
"""
|
2022-02-10 21:17:22 +01:00
|
|
|
form = ImportForm()
|
2022-02-07 18:39:32 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
file = form.fichier.data
|
2022-02-11 19:18:01 +01:00
|
|
|
file_path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR, "tmp", secure_filename(file.filename)
|
|
|
|
)
|
2022-02-08 19:13:45 +01:00
|
|
|
file.save(file_path)
|
2022-07-07 11:56:18 +02:00
|
|
|
diag, lm = sco_excel.excel_workbook_to_list(file_path)
|
2022-02-08 19:13:45 +01:00
|
|
|
os.remove(file_path)
|
2022-06-09 17:28:05 +02:00
|
|
|
if lm is None or len(lm) < 2:
|
|
|
|
flash("Veuillez utilisez la feuille excel à remplir")
|
2022-06-02 21:49:37 +02:00
|
|
|
return redirect(url_for("entreprises.import_donnees"))
|
2022-06-03 18:12:28 +02:00
|
|
|
entreprises_import = are.check_entreprises_import(lm[0])
|
2022-06-08 21:07:04 +02:00
|
|
|
sites_import, correspondants_import = are.check_sites_import(lm[1])
|
|
|
|
if (
|
|
|
|
entreprises_import is False
|
|
|
|
or sites_import is False
|
|
|
|
or correspondants_import is False
|
2022-06-09 17:28:05 +02:00
|
|
|
or (len(lm) > 2 and are.check_correspondants_import(lm[2]) is False)
|
2022-06-08 21:07:04 +02:00
|
|
|
):
|
|
|
|
return redirect(url_for("entreprises.import_donnees"))
|
2022-06-03 18:12:28 +02:00
|
|
|
for entreprise in entreprises_import:
|
2022-07-13 16:53:54 +02:00
|
|
|
try:
|
|
|
|
db.session.add(entreprise)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(entreprise)
|
|
|
|
except:
|
|
|
|
db.session.rollback()
|
|
|
|
flash("Une erreur est survenue veuillez réessayer.")
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/import_donnees.j2",
|
2022-07-13 16:53:54 +02:00
|
|
|
title="Importation données",
|
|
|
|
form=form,
|
|
|
|
)
|
2022-06-03 18:12:28 +02:00
|
|
|
site = EntrepriseSite(
|
|
|
|
entreprise_id=entreprise.id,
|
|
|
|
nom=entreprise.nom,
|
|
|
|
adresse=entreprise.adresse,
|
|
|
|
codepostal=entreprise.codepostal,
|
|
|
|
ville=entreprise.ville,
|
|
|
|
pays=entreprise.pays,
|
|
|
|
)
|
|
|
|
db.session.add(site)
|
2022-06-08 21:07:04 +02:00
|
|
|
for site in sites_import:
|
|
|
|
db.session.add(site)
|
|
|
|
correspondants = []
|
|
|
|
for site, correspondant in correspondants_import:
|
|
|
|
if site is None:
|
|
|
|
db.session.add(correspondant)
|
|
|
|
else:
|
|
|
|
db.session.add(site)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.refresh(site)
|
|
|
|
correspondant.site_id = site.id
|
|
|
|
db.session.add(correspondant)
|
|
|
|
correspondants.append(correspondant)
|
|
|
|
db.session.commit()
|
2023-04-06 16:10:32 +02:00
|
|
|
flash("Importation réussie")
|
2022-06-03 18:12:28 +02:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/import_donnees.j2",
|
2022-06-03 18:12:28 +02:00
|
|
|
title="Importation données",
|
|
|
|
form=form,
|
|
|
|
entreprises_import=entreprises_import,
|
2022-06-08 21:07:04 +02:00
|
|
|
sites_import=sites_import,
|
|
|
|
correspondants_import=correspondants,
|
2022-06-03 18:12:28 +02:00
|
|
|
)
|
2022-02-07 18:39:32 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/import_donnees.j2", title="Importation données", form=form
|
2022-02-07 18:39:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/offre/<int:offre_id>/get_offre_file/<string:filedir>/<string:filename>"
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepView)
|
2021-12-28 21:20:50 +01:00
|
|
|
def get_offre_file(entreprise_id, offre_id, filedir, filename):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de télécharger un fichier d'une offre
|
|
|
|
"""
|
2021-12-28 21:20:50 +01:00
|
|
|
if os.path.isfile(
|
|
|
|
os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
f"{filename}",
|
|
|
|
)
|
|
|
|
):
|
|
|
|
return send_file(
|
|
|
|
os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
f"{filename}",
|
|
|
|
),
|
|
|
|
as_attachment=True,
|
|
|
|
)
|
2021-12-27 11:48:58 +01:00
|
|
|
else:
|
2022-02-21 20:22:27 +01:00
|
|
|
abort(404, description=f"fichier {filename} inconnu")
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
|
2022-07-11 16:06:38 +02:00
|
|
|
@bp.route(
|
|
|
|
"/fiche_entreprise/<int:entreprise_id>/offre/<int:offre_id>/add_offre_file",
|
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def add_offre_file(entreprise_id, offre_id):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet d'ajouter un fichier à une offre
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
form = AjoutFichierForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
date = f"{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}"
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre.id}",
|
|
|
|
f"{date}",
|
|
|
|
)
|
|
|
|
os.makedirs(path)
|
|
|
|
file = form.fichier.data
|
|
|
|
filename = secure_filename(file.filename)
|
|
|
|
file.save(os.path.join(path, filename))
|
|
|
|
flash("Le fichier a été ajouté a l'offre.")
|
2022-07-11 16:06:38 +02:00
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"entreprises/form.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Ajout fichier à une offre",
|
2022-02-08 16:40:32 +01:00
|
|
|
form=form,
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
@bp.route(
|
2022-07-11 16:06:38 +02:00
|
|
|
"/fiche_entreprise/<int:entreprise_id>/offre/<int:offre_id>/delete_offre_file/<string:filedir>",
|
2022-04-13 20:59:26 +02:00
|
|
|
methods=["GET", "POST"],
|
|
|
|
)
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.RelationsEntrepEdit)
|
2022-07-11 16:06:38 +02:00
|
|
|
def delete_offre_file(entreprise_id, offre_id, filedir):
|
2021-12-29 19:40:57 +01:00
|
|
|
"""
|
|
|
|
Permet de supprimer un fichier d'une offre
|
|
|
|
"""
|
2022-07-11 16:06:38 +02:00
|
|
|
offre = EntrepriseOffre.query.filter_by(
|
|
|
|
id=offre_id, entreprise_id=entreprise_id
|
|
|
|
).first_or_404(
|
|
|
|
description=f"offre {offre_id} inconnue pour l'entreprise {entreprise_id}"
|
2022-02-21 20:22:27 +01:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
form = SuppressionConfirmationForm()
|
2022-08-23 18:54:44 +02:00
|
|
|
if request.method == "POST" and form.cancel.data:
|
|
|
|
return redirect(
|
|
|
|
url_for("entreprises.fiche_entreprise", entreprise_id=entreprise_id)
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
path = os.path.join(
|
|
|
|
Config.SCODOC_VAR_DIR,
|
|
|
|
"entreprises",
|
|
|
|
f"{offre.entreprise_id}",
|
|
|
|
f"{offre_id}",
|
|
|
|
f"{filedir}",
|
|
|
|
)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
flash("Le fichier relié à l'offre a été supprimé.")
|
|
|
|
return redirect(
|
2022-07-11 16:06:38 +02:00
|
|
|
url_for(
|
|
|
|
"entreprises.fiche_entreprise", entreprise_id=offre.entreprise_id
|
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
|
|
|
return render_template(
|
2023-09-29 21:17:31 +02:00
|
|
|
"form_confirmation.j2",
|
2022-02-11 19:18:01 +01:00
|
|
|
title="Suppression fichier d'une offre",
|
2021-12-28 21:20:50 +01:00
|
|
|
form=form,
|
2022-04-21 21:18:47 +02:00
|
|
|
info_message="Cliquez sur le bouton Supprimer pour confirmer votre supression",
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2022-02-22 21:52:32 +01:00
|
|
|
|
|
|
|
|
2022-07-08 18:56:27 +02:00
|
|
|
@bp.errorhandler(404)
|
|
|
|
def not_found_error_handler(e):
|
2022-08-10 02:27:52 +02:00
|
|
|
"""
|
|
|
|
Renvoie une page d'erreur pour l'erreur 404
|
|
|
|
"""
|
2023-01-30 22:25:17 +01:00
|
|
|
return render_template("entreprises/error.j2", title="Erreur", e=e)
|