From 2349114eb3f91fc7fedfee8a1829fa076e7447ac Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Fri, 22 Apr 2022 11:27:17 +0200 Subject: [PATCH] changement import/export correspondants, formulaires --- app/entreprises/app_relations_entreprises.py | 32 ++++++++++------- app/entreprises/models.py | 3 ++ app/entreprises/routes.py | 34 +++++++++++++------ .../entreprises/ajout_correspondants.html | 2 +- .../entreprises/import_correspondants.html | 14 ++++++-- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/app/entreprises/app_relations_entreprises.py b/app/entreprises/app_relations_entreprises.py index d0123bb2..95f1264c 100644 --- a/app/entreprises/app_relations_entreprises.py +++ b/app/entreprises/app_relations_entreprises.py @@ -131,38 +131,46 @@ def send_email_notifications_entreprise(subject, entreprise: Entreprise): def verif_correspondant_data(correspondant_data): """ Verifie les données d'une ligne Excel (correspondant) - correspondant_data[0]: nom - correspondant_data[1]: prenom - correspondant_data[2]: telephone - correspondant_data[3]: mail - correspondant_data[4]: poste - correspondant_data[5]: service - correspondant_data[6]: entreprise_siret + correspondant_data[0]: civilite + correspondant_data[1]: nom + correspondant_data[2]: prenom + correspondant_data[3]: telephone + correspondant_data[4]: mail + correspondant_data[5]: poste + correspondant_data[6]: service + correspondant_data[7]: origine + correspondant_data[8]: notes + correspondant_data[9]: entreprise_siret """ # champs obligatoires if ( correspondant_data[0].strip() == "" or correspondant_data[1].strip() == "" - or correspondant_data[6].strip() == "" + or correspondant_data[2].strip() == "" + or correspondant_data[9].strip() == "" ): return False + # civilite entre H ou F + if correspondant_data[0].strip() not in ["H", "F"]: + return False + # entreprise_id existant - entreprise = Entreprise.query.filter_by(siret=correspondant_data[6].strip()).first() + entreprise = Entreprise.query.filter_by(siret=correspondant_data[9].strip()).first() if entreprise is None: return False # correspondant possède le meme nom et prénom dans la meme entreprise correspondant = EntrepriseCorrespondant.query.filter_by( - nom=correspondant_data[0].strip(), - prenom=correspondant_data[1].strip(), + nom=correspondant_data[1].strip(), + prenom=correspondant_data[2].strip(), entreprise_id=entreprise.id, ).first() if correspondant is not None: return False if ( - correspondant_data[2].strip() == "" and correspondant_data[3].strip() == "" + correspondant_data[3].strip() == "" and correspondant_data[4].strip() == "" ): # 1 moyen de contact return False diff --git a/app/entreprises/models.py b/app/entreprises/models.py index 8ea8ef2a..f04d1a23 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -66,12 +66,15 @@ class EntrepriseCorrespondant(db.Model): def to_dict(self): entreprise = Entreprise.query.filter_by(id=self.entreprise_id).first() return { + "civilite": self.civilite, "nom": self.nom, "prenom": self.prenom, "telephone": self.telephone, "mail": self.mail, "poste": self.poste, "service": self.service, + "origine": self.origine, + "notes": self.notes, "entreprise_siret": entreprise.siret, } diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 107aa436..d7c6ec13 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -1287,12 +1287,15 @@ def export_correspondants(): ) if correspondants: keys = [ + "civilite", "nom", "prenom", "telephone", "mail", "poste", "service", + "origine", + "notes", "entreprise_siret", ] titles = keys[:] @@ -1316,12 +1319,15 @@ def get_import_correspondants_file_sample(): Permet de récupérer un fichier exemple vide pour pouvoir importer des correspondants """ keys = [ + "civilite", "nom", "prenom", "telephone", "mail", "poste", "service", + "origine", + "notes", "entreprise_siret", ] titles = keys[:] @@ -1350,12 +1356,15 @@ def import_correspondants(): correspondant_list = [] ligne = 0 titles = [ + "civilite", "nom", "prenom", "telephone", "mail", "poste", "service", + "origine", + "notes", "entreprise_siret", ] if data[1][0] != titles: @@ -1370,29 +1379,32 @@ def import_correspondants(): if ( are.verif_correspondant_data(correspondant_data) and ( - correspondant_data[0].strip(), correspondant_data[1].strip(), - correspondant_data[6].strip(), + correspondant_data[2].strip(), + correspondant_data[9].strip(), ) not in correspondant_list ): correspondant_list.append( ( - correspondant_data[0].strip(), correspondant_data[1].strip(), - correspondant_data[6].strip(), + correspondant_data[2].strip(), + correspondant_data[9].strip(), ) ) entreprise = Entreprise.query.filter_by( - siret=correspondant_data[6].strip() + siret=correspondant_data[9].strip() ).first() correspondant = EntrepriseCorrespondant( - nom=correspondant_data[0].strip(), - prenom=correspondant_data[1].strip(), - telephone=correspondant_data[2].strip(), - mail=correspondant_data[3].strip(), - poste=correspondant_data[4].strip(), - service=correspondant_data[5].strip(), + civilite=correspondant_data[0].strip(), + nom=correspondant_data[1].strip(), + prenom=correspondant_data[2].strip(), + telephone=correspondant_data[3].strip(), + mail=correspondant_data[4].strip(), + poste=correspondant_data[5].strip(), + service=correspondant_data[6].strip(), + origine=correspondant_data[7].strip(), + notes=correspondant_data[8].strip(), entreprise_id=entreprise.id, ) correspondants_import.append(correspondant) diff --git a/app/templates/entreprises/ajout_correspondants.html b/app/templates/entreprises/ajout_correspondants.html index f7d5e5b1..be8e5cc8 100644 --- a/app/templates/entreprises/ajout_correspondants.html +++ b/app/templates/entreprises/ajout_correspondants.html @@ -48,7 +48,7 @@ } let newFieldName = `correspondants-${Math.max(...correspondantInputIds) + 1}`; allCorrepondantsFieldWrapper.insertAdjacentHTML('beforeend',` -
  • +
  • `); }); } diff --git a/app/templates/entreprises/import_correspondants.html b/app/templates/entreprises/import_correspondants.html index cfbaf11a..796c2135 100644 --- a/app/templates/entreprises/import_correspondants.html +++ b/app/templates/entreprises/import_correspondants.html @@ -25,13 +25,16 @@ {% if not correspondants_import %} + - + + +
    AttributTypeDescription
    civilitetextcivilite du correspondant (H ou F)
    nomtextnom du correspondant
    prenomtextprenom du correspondant
    telephonetexttelephone du correspondant
    mailtextmail du correspondant
    postetextposte du correspondant
    servicetextservice dans lequel travaille le correspondant
    entreprise_siretintegerSIRET de l'entreprise
    originetextorigine du correspondant
    notestextnotes sur le correspondant
    entreprise_sirettextSIRET de l'entreprise
    {% endif %} @@ -40,6 +43,7 @@ {% for correspondant in correspondants_import %}
    + Civilité : {{ correspondant.civilite|get_civilité }}
    Nom : {{ correspondant.nom }}
    Prénom : {{ correspondant.prenom }}
    {% if correspondant.telephone %} @@ -54,7 +58,13 @@ {% if correspondant.service %} Service : {{ correspondant.service }}
    {% endif %} - lien vers l'entreprise + {% if correspondant.origine %} + Origine : {{ correspondant.origine }}
    + {% endif %} + {% if correspondant.notes %} + Notes : {{ correspondant.notes }}
    + {% endif %} + lien vers l'entreprise
    {% endfor %}