diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 335f7004..5d89aa71 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -62,6 +62,7 @@ from app.entreprises.models import ( EntrepriseSite, EntrepriseTaxeApprentissage, ) +from app import db from app.models import Identite, Departement from app.auth.models import User @@ -277,9 +278,10 @@ class OffreCreationForm(FlaskForm): self.correspondant.choices = [("", "")] + [ (correspondant.id, f"{correspondant.nom} {correspondant.prenom}") - for correspondant in EntrepriseCorrespondant.query.filter_by( - entreprise_id=self.hidden_entreprise_id.data - ) + for correspondant in db.session.query(EntrepriseCorrespondant) + .join(EntrepriseSite, EntrepriseCorrespondant.site_id == EntrepriseSite.id) + .filter(EntrepriseSite.entreprise_id == self.hidden_entreprise_id.data) + .all() ] self.depts.choices = [ @@ -323,9 +325,10 @@ class OffreModificationForm(FlaskForm): self.correspondant.choices = [("", "")] + [ (correspondant.id, f"{correspondant.nom} {correspondant.prenom}") - for correspondant in EntrepriseCorrespondant.query.filter_by( - entreprise_id=self.hidden_entreprise_id.data - ) + for correspondant in db.session.query(EntrepriseCorrespondant) + .join(EntrepriseSite, EntrepriseCorrespondant.site_id == EntrepriseSite.id) + .filter(EntrepriseSite.entreprise_id == self.hidden_entreprise_id.data) + .all() ] self.depts.choices = [