2021-12-23 19:28:25 +01:00
|
|
|
from app import db
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class Entreprise(db.Model):
|
2022-01-24 11:16:46 +01:00
|
|
|
__tablename__ = "are_entreprises"
|
2021-12-23 19:28:25 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-07-12 10:32:23 +02:00
|
|
|
siret = db.Column(db.Text, index=True)
|
|
|
|
siret_provisoire = db.Column(db.Boolean, default=False)
|
2021-12-23 19:28:25 +01:00
|
|
|
nom = db.Column(db.Text)
|
|
|
|
adresse = db.Column(db.Text)
|
|
|
|
codepostal = db.Column(db.Text)
|
|
|
|
ville = db.Column(db.Text)
|
2022-04-25 20:49:21 +02:00
|
|
|
pays = db.Column(db.Text)
|
2022-05-06 01:33:50 +02:00
|
|
|
association = db.Column(db.Boolean, default=False)
|
2022-01-25 19:42:17 +01:00
|
|
|
visible = db.Column(db.Boolean, default=False)
|
2022-04-20 22:37:04 +02:00
|
|
|
active = db.Column(db.Boolean, default=True)
|
2022-04-21 21:18:47 +02:00
|
|
|
notes_active = db.Column(db.Text)
|
2022-04-25 20:49:21 +02:00
|
|
|
|
|
|
|
sites = db.relationship(
|
|
|
|
"EntrepriseSite",
|
2021-12-28 21:20:50 +01:00
|
|
|
backref="entreprise",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
2022-04-25 20:49:21 +02:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
offres = db.relationship(
|
|
|
|
"EntrepriseOffre",
|
|
|
|
backref="entreprise",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
def to_dict(self):
|
2021-12-24 18:10:19 +01:00
|
|
|
return {
|
|
|
|
"siret": self.siret,
|
2022-02-22 21:52:32 +01:00
|
|
|
"nom_entreprise": self.nom,
|
2021-12-24 18:10:19 +01:00
|
|
|
"adresse": self.adresse,
|
2022-02-10 21:17:22 +01:00
|
|
|
"code_postal": self.codepostal,
|
2021-12-27 11:48:58 +01:00
|
|
|
"ville": self.ville,
|
2021-12-28 21:20:50 +01:00
|
|
|
"pays": self.pays,
|
2022-05-31 19:15:24 +02:00
|
|
|
"association": self.association,
|
|
|
|
"visible": self.visible,
|
|
|
|
"active": self.active,
|
|
|
|
"notes_active": self.notes_active,
|
2021-12-24 18:10:19 +01:00
|
|
|
}
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-25 20:49:21 +02:00
|
|
|
class EntrepriseSite(db.Model):
|
|
|
|
__tablename__ = "are_sites"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
entreprise_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
|
|
|
)
|
|
|
|
nom = db.Column(db.Text)
|
|
|
|
adresse = db.Column(db.Text)
|
|
|
|
codepostal = db.Column(db.Text)
|
|
|
|
ville = db.Column(db.Text)
|
|
|
|
pays = db.Column(db.Text)
|
|
|
|
|
|
|
|
correspondants = db.relationship(
|
|
|
|
"EntrepriseCorrespondant",
|
|
|
|
backref="site",
|
|
|
|
lazy="dynamic",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
)
|
2022-04-13 20:59:26 +02:00
|
|
|
|
2022-05-31 19:15:24 +02:00
|
|
|
def to_dict(self):
|
|
|
|
entreprise = Entreprise.query.get_or_404(self.entreprise_id)
|
|
|
|
return {
|
|
|
|
"siret_entreprise": entreprise.siret,
|
2022-06-10 17:55:59 +02:00
|
|
|
"id_site": self.id,
|
2022-05-31 19:15:24 +02:00
|
|
|
"nom_site": self.nom,
|
|
|
|
"adresse": self.adresse,
|
|
|
|
"code_postal": self.codepostal,
|
|
|
|
"ville": self.ville,
|
|
|
|
"pays": self.pays,
|
|
|
|
}
|
|
|
|
|
2022-04-13 20:59:26 +02:00
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
class EntrepriseCorrespondant(db.Model):
|
|
|
|
__tablename__ = "are_correspondants"
|
2021-12-23 19:28:25 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-04-25 20:49:21 +02:00
|
|
|
site_id = db.Column(db.Integer, db.ForeignKey("are_sites.id", ondelete="cascade"))
|
2022-04-20 22:37:04 +02:00
|
|
|
civilite = db.Column(db.String(1))
|
2021-12-23 19:28:25 +01:00
|
|
|
nom = db.Column(db.Text)
|
|
|
|
prenom = db.Column(db.Text)
|
|
|
|
telephone = db.Column(db.Text)
|
|
|
|
mail = db.Column(db.Text)
|
2021-12-24 10:43:12 +01:00
|
|
|
poste = db.Column(db.Text)
|
|
|
|
service = db.Column(db.Text)
|
2022-04-20 22:37:04 +02:00
|
|
|
origine = db.Column(db.Text)
|
|
|
|
notes = db.Column(db.Text)
|
2021-12-28 21:20:50 +01:00
|
|
|
|
|
|
|
def to_dict(self):
|
2022-06-01 21:17:15 +02:00
|
|
|
site = EntrepriseSite.query.get_or_404(self.site_id)
|
2021-12-27 11:48:58 +01:00
|
|
|
return {
|
2022-06-01 21:17:15 +02:00
|
|
|
"id": self.id,
|
2022-04-22 11:27:17 +02:00
|
|
|
"civilite": self.civilite,
|
2021-12-27 11:48:58 +01:00
|
|
|
"nom": self.nom,
|
|
|
|
"prenom": self.prenom,
|
|
|
|
"telephone": self.telephone,
|
|
|
|
"mail": self.mail,
|
|
|
|
"poste": self.poste,
|
2021-12-28 21:20:50 +01:00
|
|
|
"service": self.service,
|
2022-04-22 11:27:17 +02:00
|
|
|
"origine": self.origine,
|
|
|
|
"notes": self.notes,
|
2022-06-01 21:17:15 +02:00
|
|
|
"nom_site": site.nom,
|
2021-12-29 19:40:57 +01:00
|
|
|
}
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-04-05 02:26:43 +02:00
|
|
|
class EntrepriseContact(db.Model):
|
|
|
|
__tablename__ = "are_contacts"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
date = db.Column(db.DateTime(timezone=True))
|
|
|
|
user = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade"))
|
|
|
|
entreprise = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
|
|
|
)
|
|
|
|
notes = db.Column(db.Text)
|
|
|
|
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
class EntrepriseOffre(db.Model):
|
2022-03-01 18:45:04 +01:00
|
|
|
__tablename__ = "are_offres"
|
2021-12-23 19:28:25 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-12-28 21:20:50 +01:00
|
|
|
entreprise_id = db.Column(
|
2022-01-24 11:16:46 +01:00
|
|
|
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
2021-12-28 21:20:50 +01:00
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
date_ajout = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
intitule = db.Column(db.Text)
|
|
|
|
description = db.Column(db.Text)
|
|
|
|
type_offre = db.Column(db.Text)
|
|
|
|
missions = db.Column(db.Text)
|
|
|
|
duree = db.Column(db.Text)
|
2022-01-24 18:07:54 +01:00
|
|
|
expiration_date = db.Column(db.Date)
|
2022-03-01 18:45:04 +01:00
|
|
|
expired = db.Column(db.Boolean, default=False)
|
2022-03-28 23:44:57 +02:00
|
|
|
correspondant_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("are_correspondants.id", ondelete="cascade")
|
2022-03-04 17:10:07 +01:00
|
|
|
)
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2021-12-30 19:37:46 +01:00
|
|
|
def to_dict(self):
|
|
|
|
return {
|
|
|
|
"intitule": self.intitule,
|
|
|
|
"description": self.description,
|
|
|
|
"type_offre": self.type_offre,
|
|
|
|
"missions": self.missions,
|
|
|
|
"duree": self.duree,
|
|
|
|
}
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
|
2022-07-04 21:12:56 +02:00
|
|
|
class EntrepriseHistorique(db.Model):
|
|
|
|
__tablename__ = "are_historique"
|
2021-12-23 19:28:25 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
authenticated_user = db.Column(db.Text)
|
2022-05-06 18:50:12 +02:00
|
|
|
entreprise_id = db.Column(db.Integer)
|
|
|
|
object = db.Column(db.Text)
|
|
|
|
object_id = db.Column(db.Integer)
|
2021-12-23 19:28:25 +01:00
|
|
|
text = db.Column(db.Text)
|
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-03-28 23:44:57 +02:00
|
|
|
class EntrepriseStageApprentissage(db.Model):
|
|
|
|
__tablename__ = "are_stages_apprentissages"
|
2021-12-23 19:28:25 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-02-04 17:12:56 +01:00
|
|
|
entreprise_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
|
|
|
)
|
2021-12-23 19:28:25 +01:00
|
|
|
etudid = db.Column(db.Integer)
|
|
|
|
type_offre = db.Column(db.Text)
|
|
|
|
date_debut = db.Column(db.Date)
|
|
|
|
date_fin = db.Column(db.Date)
|
|
|
|
formation_text = db.Column(db.Text)
|
|
|
|
formation_scodoc = db.Column(db.Integer)
|
2022-03-29 19:07:59 +02:00
|
|
|
notes = db.Column(db.Text)
|
2021-12-24 10:43:12 +01:00
|
|
|
|
2021-12-28 21:20:50 +01:00
|
|
|
|
2022-05-04 18:59:29 +02:00
|
|
|
class EntrepriseTaxeApprentissage(db.Model):
|
|
|
|
__tablename__ = "are_taxe_apprentissage"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
entreprise_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
|
|
|
)
|
|
|
|
annee = db.Column(db.Integer)
|
|
|
|
montant = db.Column(db.Integer)
|
|
|
|
notes = db.Column(db.Text)
|
|
|
|
|
|
|
|
|
2021-12-24 10:43:12 +01:00
|
|
|
class EntrepriseEnvoiOffre(db.Model):
|
2022-03-01 18:45:04 +01:00
|
|
|
__tablename__ = "are_envoi_offre"
|
2021-12-24 10:43:12 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-02-04 17:12:56 +01:00
|
|
|
sender_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade"))
|
|
|
|
receiver_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade"))
|
2022-03-01 18:45:04 +01:00
|
|
|
offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade"))
|
2021-12-28 21:20:50 +01:00
|
|
|
date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
2021-12-30 19:37:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EntrepriseEnvoiOffreEtudiant(db.Model):
|
2022-03-01 18:45:04 +01:00
|
|
|
__tablename__ = "are_envoi_offre_etudiant"
|
2021-12-30 19:37:46 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-02-04 17:12:56 +01:00
|
|
|
sender_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade"))
|
|
|
|
receiver_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("identite.id", ondelete="cascade")
|
|
|
|
)
|
2022-03-01 18:45:04 +01:00
|
|
|
offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade"))
|
2021-12-30 19:37:46 +01:00
|
|
|
date_envoi = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
2022-02-03 16:53:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EntrepriseOffreDepartement(db.Model):
|
2022-03-01 18:45:04 +01:00
|
|
|
__tablename__ = "are_offre_departement"
|
2022-02-03 16:53:59 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2022-03-01 18:45:04 +01:00
|
|
|
offre_id = db.Column(db.Integer, db.ForeignKey("are_offres.id", ondelete="cascade"))
|
2022-02-04 17:12:56 +01:00
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id", ondelete="cascade"))
|
2022-02-22 21:52:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EntreprisePreferences(db.Model):
|
|
|
|
__tablename__ = "are_preferences"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text)
|
|
|
|
value = db.Column(db.Text)
|
2022-02-23 19:12:26 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_email_notifications(cls):
|
|
|
|
mail = EntreprisePreferences.query.filter_by(
|
|
|
|
name="mail_notifications_entreprise"
|
|
|
|
).first()
|
|
|
|
if mail is None:
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return mail.value
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_email_notifications(cls, mail: str):
|
|
|
|
if mail != cls.get_email_notifications():
|
|
|
|
m = EntreprisePreferences.query.filter_by(
|
|
|
|
name="mail_notifications_entreprise"
|
|
|
|
).first()
|
|
|
|
if m is None:
|
|
|
|
prefs = EntreprisePreferences(
|
|
|
|
name="mail_notifications_entreprise",
|
|
|
|
value=mail,
|
|
|
|
)
|
|
|
|
db.session.add(prefs)
|
|
|
|
else:
|
|
|
|
m.value = mail
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_check_siret(cls):
|
|
|
|
check_siret = EntreprisePreferences.query.filter_by(name="check_siret").first()
|
|
|
|
if check_siret is None:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return int(check_siret.value)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set_check_siret(cls, check_siret: int):
|
|
|
|
cs = EntreprisePreferences.query.filter_by(name="check_siret").first()
|
|
|
|
if cs is None:
|
|
|
|
prefs = EntreprisePreferences(name="check_siret", value=check_siret)
|
|
|
|
db.session.add(prefs)
|
|
|
|
else:
|
|
|
|
cs.value = check_siret
|
|
|
|
db.session.commit()
|
2022-07-13 12:14:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def entreprises_reset_database():
|
|
|
|
db.session.query(EntrepriseContact).delete()
|
|
|
|
db.session.query(EntrepriseStageApprentissage).delete()
|
|
|
|
db.session.query(EntrepriseTaxeApprentissage).delete()
|
|
|
|
db.session.query(EntrepriseCorrespondant).delete()
|
|
|
|
db.session.query(EntrepriseSite).delete()
|
|
|
|
db.session.query(EntrepriseEnvoiOffre).delete()
|
|
|
|
db.session.query(EntrepriseEnvoiOffreEtudiant).delete()
|
|
|
|
db.session.query(EntrepriseOffreDepartement).delete()
|
|
|
|
db.session.query(EntrepriseOffre).delete()
|
|
|
|
db.session.query(Entreprise).delete()
|
|
|
|
db.session.query(EntrepriseHistorique).delete()
|
|
|
|
db.session.query(EntreprisePreferences).delete()
|
|
|
|
db.session.commit()
|