forked from ScoDoc/ScoDoc
import entreprises par fichier excel, divers corrections
This commit is contained in:
parent
acb8d58642
commit
f1bb718f08
@ -879,9 +879,8 @@ def get_import_entreprises_file_sample():
|
||||
|
||||
|
||||
def verif_entreprise_data(entreprise_data):
|
||||
print(entreprise_data)
|
||||
for data in entreprise_data:
|
||||
if data is "":
|
||||
if data == "":
|
||||
return False
|
||||
siret = entreprise_data[0].strip()
|
||||
if re.match("^\d{14}$", siret) is None:
|
||||
@ -911,8 +910,16 @@ def import_entreprises():
|
||||
data = sco_excel.excel_file_to_list(file_path)
|
||||
os.remove(file_path)
|
||||
entreprises_import = []
|
||||
siret_list = []
|
||||
ligne = 0
|
||||
|
||||
for entreprise_data in data[1][1:]:
|
||||
if verif_entreprise_data(entreprise_data):
|
||||
ligne += 1
|
||||
if (
|
||||
verif_entreprise_data(entreprise_data)
|
||||
and entreprise_data[0] not in siret_list
|
||||
):
|
||||
siret_list.append(entreprise_data[0])
|
||||
entreprise = Entreprise(
|
||||
siret=entreprise_data[0],
|
||||
nom=entreprise_data[1],
|
||||
@ -920,14 +927,32 @@ def import_entreprises():
|
||||
ville=entreprise_data[3],
|
||||
codepostal=entreprise_data[4],
|
||||
pays=entreprise_data[5],
|
||||
visible=True,
|
||||
)
|
||||
entreprises_import.append(entreprise)
|
||||
|
||||
else:
|
||||
flash(f"Erreur lors de l'importation (ligne {ligne})")
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
form=form,
|
||||
)
|
||||
|
||||
if len(entreprises_import) > 0:
|
||||
for entreprise in entreprises_import:
|
||||
db.session.add(entreprise)
|
||||
db.session.commit()
|
||||
flash(f"Importation réussie de {len(entreprises_import)} entreprise(s)")
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
form=form,
|
||||
entreprises_import=entreprises_import,
|
||||
)
|
||||
else:
|
||||
flash('Feuille "Entreprises" vide')
|
||||
|
||||
return render_template(
|
||||
"entreprises/import_entreprises.html",
|
||||
title=("Importation entreprises"),
|
||||
|
@ -15,7 +15,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) %}
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) and contacts.items %}
|
||||
<div class="container boutons">
|
||||
{% if contacts %}
|
||||
<a class="btn btn-default" href="{{ url_for('entreprises.export_contacts') }}">Exporter la liste des contacts</a>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<a class="btn btn-default" href="{{ url_for('entreprises.import_entreprises') }}">Importer des entreprises</a>
|
||||
{% endif %}
|
||||
{% if entreprises %}
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) %}
|
||||
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) and entreprises.items%}
|
||||
<a class="btn btn-default" href="{{ url_for('entreprises.export_entreprises') }}">Exporter la liste des entreprises</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -20,6 +20,7 @@
|
||||
</div>
|
||||
|
||||
{% if entreprises_import %}
|
||||
<br><div>Importation de {{ entreprises_import|length }} entreprise(s)</div>
|
||||
{% for entreprise in entreprises_import %}
|
||||
<div class="entreprise">
|
||||
<div>
|
||||
@ -32,8 +33,5 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<a class="btn btn-default" href="#">Ajouter</a>
|
||||
{% else %}
|
||||
<div>Aucune entreprise importée (vérifier le fichier .xlsx)</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user