forked from ScoDoc/ScoDoc
correction suite aux changements, suite import export
This commit is contained in:
parent
8e95996930
commit
e96d714545
@ -38,10 +38,11 @@ from app.entreprises.models import (
|
||||
EntrepriseOffre,
|
||||
EntrepriseOffreDepartement,
|
||||
EntreprisePreferences,
|
||||
EntrepriseSite,
|
||||
)
|
||||
|
||||
from app import email
|
||||
from app import email, db
|
||||
from app.scodoc import sco_preferences
|
||||
from app.scodoc import sco_excel
|
||||
from app.models import Departement
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
|
||||
@ -212,3 +213,75 @@ def verif_entreprise_data(entreprise_data):
|
||||
if entreprise is not None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_excel_book_are(export=False):
|
||||
entreprises_keys = [
|
||||
"siret",
|
||||
"nom_entreprise",
|
||||
"adresse",
|
||||
"ville",
|
||||
"code_postal",
|
||||
"pays",
|
||||
"association",
|
||||
"visible",
|
||||
"active",
|
||||
"notes_active",
|
||||
]
|
||||
sites_keys = [
|
||||
"siret_entreprise",
|
||||
"nom_site",
|
||||
"adresse",
|
||||
"ville",
|
||||
"code_postal",
|
||||
"pays",
|
||||
]
|
||||
entreprises_titles = entreprises_keys[:]
|
||||
sites_titles = sites_keys[:]
|
||||
wb = sco_excel.ScoExcelBook()
|
||||
ws1 = wb.create_sheet("Entreprises")
|
||||
ws1.append_row(
|
||||
[
|
||||
ws1.make_cell(it, style)
|
||||
for (it, style) in zip(
|
||||
entreprises_titles,
|
||||
[sco_excel.excel_make_style(bold=True)] * len(entreprises_titles),
|
||||
)
|
||||
]
|
||||
)
|
||||
ws2 = wb.create_sheet("Sites")
|
||||
ws2.append_row(
|
||||
[
|
||||
ws2.make_cell(it, style)
|
||||
for (it, style) in zip(
|
||||
sites_titles,
|
||||
[sco_excel.excel_make_style(bold=True)] * len(sites_titles),
|
||||
)
|
||||
]
|
||||
)
|
||||
if export:
|
||||
entreprises = Entreprise.query.filter_by(visible=True).all()
|
||||
sites = (
|
||||
db.session.query(EntrepriseSite)
|
||||
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
|
||||
.filter_by(visible=True)
|
||||
.all()
|
||||
)
|
||||
entreprises_lines = [
|
||||
[entreprise.to_dict().get(k, "") for k in entreprises_keys]
|
||||
for entreprise in entreprises
|
||||
]
|
||||
sites_lines = [
|
||||
[site.to_dict().get(k, "") for k in sites_keys] for site in sites
|
||||
]
|
||||
for line in entreprises_lines:
|
||||
cells = []
|
||||
for it in line:
|
||||
cells.append(ws1.make_cell(it))
|
||||
ws1.append_row(cells)
|
||||
for line in sites_lines:
|
||||
cells = []
|
||||
for it in line:
|
||||
cells.append(ws2.make_cell(it))
|
||||
ws2.append_row(cells)
|
||||
return wb
|
||||
|
@ -37,6 +37,10 @@ class Entreprise(db.Model):
|
||||
"code_postal": self.codepostal,
|
||||
"ville": self.ville,
|
||||
"pays": self.pays,
|
||||
"association": self.association,
|
||||
"visible": self.visible,
|
||||
"active": self.active,
|
||||
"notes_active": self.notes_active,
|
||||
}
|
||||
|
||||
|
||||
@ -59,6 +63,17 @@ class EntrepriseSite(db.Model):
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
entreprise = Entreprise.query.get_or_404(self.entreprise_id)
|
||||
return {
|
||||
"siret_entreprise": entreprise.siret,
|
||||
"nom_site": self.nom,
|
||||
"adresse": self.adresse,
|
||||
"code_postal": self.codepostal,
|
||||
"ville": self.ville,
|
||||
"pays": self.pays,
|
||||
}
|
||||
|
||||
|
||||
class EntrepriseCorrespondant(db.Model):
|
||||
__tablename__ = "are_correspondants"
|
||||
|
@ -138,6 +138,7 @@ def correspondants():
|
||||
.join(EntrepriseSite, EntrepriseCorrespondant.site_id == EntrepriseSite.id)
|
||||
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
|
||||
.filter_by(visible=True, active=True)
|
||||
.all()
|
||||
)
|
||||
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
|
||||
return render_template(
|
||||
@ -216,7 +217,7 @@ def logs_entreprise(id):
|
||||
)
|
||||
logs = (
|
||||
EntrepriseLog.query.order_by(EntrepriseLog.date.desc())
|
||||
.filter(EntrepriseLog.entreprise_id == id)
|
||||
.filter(EntrepriseLog.entreprise_id == entreprise.id)
|
||||
.paginate(page=page, per_page=20)
|
||||
)
|
||||
return render_template(
|
||||
@ -236,12 +237,12 @@ def fiche_entreprise_validation(id):
|
||||
entreprise = Entreprise.query.filter_by(id=id, visible=False).first_or_404(
|
||||
description=f"fiche entreprise (validation) {id} inconnue"
|
||||
)
|
||||
correspondants = entreprise.correspondants
|
||||
sites = entreprise.sites[:]
|
||||
return render_template(
|
||||
"entreprises/fiche_entreprise_validation.html",
|
||||
title="Validation fiche entreprise",
|
||||
entreprise=entreprise,
|
||||
correspondants=correspondants,
|
||||
sites=sites,
|
||||
)
|
||||
|
||||
|
||||
@ -875,8 +876,11 @@ def add_site(id):
|
||||
methods=["GET", "POST"],
|
||||
)
|
||||
def edit_site(id_entreprise, id_site):
|
||||
entreprise = Entreprise.query.filter_by(
|
||||
id=id_entreprise, visible=True
|
||||
).first_or_404(description=f"entreprise {id_entreprise} inconnue")
|
||||
site = EntrepriseSite.query.filter_by(
|
||||
id=id_site, entreprise_id=id_entreprise
|
||||
id=id_site, entreprise_id=entreprise.id
|
||||
).first_or_404(description=f"site {id_site} inconnu")
|
||||
form = SiteModificationForm(
|
||||
hidden_entreprise_id=id_entreprise, hidden_site_id=id_site
|
||||
@ -960,8 +964,11 @@ def edit_correspondant(id):
|
||||
"""
|
||||
Permet de modifier un correspondant
|
||||
"""
|
||||
correspondant = EntrepriseCorrespondant.query.filter_by(id=id).first_or_404(
|
||||
description=f"correspondant {id} inconnu"
|
||||
correspondant = (
|
||||
db.session.query(EntrepriseCorrespondant)
|
||||
.join(Entreprise, EntrepriseCorrespondant.entreprise_id == Entreprise.id)
|
||||
.filter(EntrepriseCorrespondant.id == id, Entreprise.visible == True)
|
||||
.first_or_404(description=f"correspondant {id} inconnu")
|
||||
)
|
||||
form = CorrespondantModificationForm(
|
||||
hidden_entreprise_id=correspondant.entreprise_id,
|
||||
@ -1013,8 +1020,11 @@ def delete_correspondant(id):
|
||||
"""
|
||||
Permet de supprimer un correspondant
|
||||
"""
|
||||
correspondant = EntrepriseCorrespondant.query.filter_by(id=id).first_or_404(
|
||||
description=f"correspondant {id} inconnu"
|
||||
correspondant = (
|
||||
db.session.query(EntrepriseCorrespondant)
|
||||
.join(Entreprise, EntrepriseCorrespondant.entreprise_id == Entreprise.id)
|
||||
.filter(EntrepriseCorrespondant.id == id, Entreprise.visible == True)
|
||||
.first_or_404(description=f"correspondant {id} inconnu")
|
||||
)
|
||||
form = SuppressionConfirmationForm()
|
||||
if form.validate_on_submit():
|
||||
@ -1126,7 +1136,10 @@ def contacts(id):
|
||||
"""
|
||||
Permet d'afficher une page avec la liste des contacts d'une entreprise
|
||||
"""
|
||||
contacts = EntrepriseContact.query.filter_by(entreprise=id).all()
|
||||
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
||||
description=f"entreprise {id} inconnue"
|
||||
)
|
||||
contacts = EntrepriseContact.query.filter_by(entreprise=entreprise.id).all()
|
||||
return render_template(
|
||||
"entreprises/contacts.html",
|
||||
title="Liste des contacts",
|
||||
@ -1367,17 +1380,11 @@ def export_entreprises():
|
||||
"""
|
||||
Permet d'exporter la liste des entreprises sous format excel (.xlsx)
|
||||
"""
|
||||
entreprises = Entreprise.query.filter_by(visible=True).all()
|
||||
if entreprises:
|
||||
keys = ["siret", "nom_entreprise", "adresse", "ville", "code_postal", "pays"]
|
||||
titles = keys[:]
|
||||
L = [
|
||||
[entreprise.to_dict().get(k, "") for k in keys]
|
||||
for entreprise in entreprises
|
||||
]
|
||||
title = "Entreprises"
|
||||
xlsx = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
|
||||
filename = title
|
||||
entreprise = Entreprise.query.filter_by(visible=True).first()
|
||||
if entreprise:
|
||||
wb = are.get_excel_book_are(export=True)
|
||||
xlsx = wb.generate()
|
||||
filename = "ExportEntreprisesSites"
|
||||
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
||||
else:
|
||||
flash("Aucune entreprise dans la base.")
|
||||
@ -1390,48 +1397,9 @@ def get_import_entreprises_file_sample():
|
||||
"""
|
||||
Permet de récupérer un fichier exemple vide pour pouvoir importer des entreprises
|
||||
"""
|
||||
entreprises_titles = [
|
||||
"siret",
|
||||
"nom_entreprise",
|
||||
"adresse",
|
||||
"ville",
|
||||
"code_postal",
|
||||
"pays",
|
||||
]
|
||||
sites_titles = [
|
||||
"siret_entreprise",
|
||||
"nom_site",
|
||||
"adresse",
|
||||
"ville",
|
||||
"code_postal",
|
||||
"pays",
|
||||
]
|
||||
title = "ImportEntreprises"
|
||||
wb = sco_excel.ScoExcelBook()
|
||||
ws1 = wb.create_sheet("Entreprises")
|
||||
ws1.append_row(
|
||||
[
|
||||
ws1.make_cell(it, style, comment)
|
||||
for (it, style, comment) in zip(
|
||||
entreprises_titles,
|
||||
[sco_excel.excel_make_style(bold=True)] * len(entreprises_titles),
|
||||
[None] * len(entreprises_titles),
|
||||
)
|
||||
]
|
||||
)
|
||||
ws2 = wb.create_sheet("Sites")
|
||||
ws2.append_row(
|
||||
[
|
||||
ws2.make_cell(it, style, comment)
|
||||
for (it, style, comment) in zip(
|
||||
sites_titles,
|
||||
[sco_excel.excel_make_style(bold=True)] * len(sites_titles),
|
||||
[None] * len(sites_titles),
|
||||
)
|
||||
]
|
||||
)
|
||||
wb = are.get_excel_book_are()
|
||||
xlsx = wb.generate()
|
||||
filename = title
|
||||
filename = "ImportEntreprisesSites"
|
||||
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
|
||||
|
||||
|
||||
|
@ -19,31 +19,51 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if correspondants %}
|
||||
<div>
|
||||
{% for correspondant in correspondants %}
|
||||
<div class="sites-et-offres">
|
||||
{% if sites %}
|
||||
<div>
|
||||
<h3>Correspondant</h3>
|
||||
<div class="correspondant">
|
||||
Nom : {{ correspondant.nom }}<br>
|
||||
Prénom : {{ correspondant.prenom }}<br>
|
||||
{% if correspondant.telephone %}
|
||||
Téléphone : {{ correspondant.telephone }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.mail %}
|
||||
Mail : {{ correspondant.mail }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.poste %}
|
||||
Poste : {{ correspondant.poste }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.service %}
|
||||
Service : {{ correspondant.service }}<br>
|
||||
<h3>Sites</h3>
|
||||
{% for site in sites %}
|
||||
<div class="site">
|
||||
Nom : {{ site.nom }}<br>
|
||||
Adresse : {{ site.adresse }}<br>
|
||||
Code postal : {{ site.codepostal }}<br>
|
||||
Ville : {{ site.ville }}<br>
|
||||
Pays : {{ site.pays }}
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesCorrespondants, None) %}
|
||||
{% for correspondant in site.correspondants %}
|
||||
<div class="correspondant">
|
||||
<div>
|
||||
Civilité : {{ correspondant.civilite|get_civilité }}<br>
|
||||
Nom : {{ correspondant.nom }}<br>
|
||||
Prénom : {{ correspondant.prenom }}<br>
|
||||
{% if correspondant.telephone %}
|
||||
Téléphone : {{ correspondant.telephone }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.mail %}
|
||||
Mail : {{ correspondant.mail }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.poste %}
|
||||
Poste : {{ correspondant.poste }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.service %}
|
||||
Service : {{ correspondant.service }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.origine %}
|
||||
Origine : {{ correspondant.origine }}<br>
|
||||
{% endif %}
|
||||
{% if correspondant.notes %}
|
||||
Notes : {{ correspondant.notes }}<br>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<a class="btn btn-success" href="{{ url_for('entreprises.validate_entreprise', id=entreprise.id) }}">Valider</a>
|
||||
|
Loading…
Reference in New Issue
Block a user