ajout import de la table relou... (tarifs IMH)

This commit is contained in:
cthienan
2021-07-26 15:21:06 +02:00
parent 5b8c73caea
commit d47e2a2378

View File

@@ -687,7 +687,7 @@ def societe_edit(request):
def tarifs(request):
groupe = request.matchdict['groupe']
groupes = ["AXA", "MAIF", "TEXTE"]
groupes = ["AXA", "MAIF", "IMH", "TEXTE"]
# si table a changé
if 'groupe' in request.params:
@@ -775,7 +775,7 @@ def tarifs_import(request):
url = request.route_url("tarifs_import")
message = ''
groupes = ['AXA','MAIF']
groupes = ['AXA','MAIF', 'IMH']
groupe = 'AXA'
@@ -852,7 +852,7 @@ def tarifs_import(request):
if sh.cell_type(rx, 5) == 2:
new_values['prixht'] = sh.cell_value(rx, 5)
# col Unité renseigné ?
if sh.cell_type(rx, 5) != 0:
if sh.cell_type(rx, 3) != 0:
unite = sh.cell_value(rx, 3)
else:
if sh.cell_value(rx, 1).find(' m2'):
@@ -861,6 +861,66 @@ def tarifs_import(request):
unite = 'U'
new_values['unite'] = unite
update_tarif(request, '0', new_values)
elif groupe == "IMH":
# lire la 1ère feuille et contôler que c'est fichier IMH
sh = book.sheet_by_index(0)
ctl_cellA1 = sh.cell_value(rowx=0, colx=0)
if ctl_cellA1 != 'CO-FORI0':
request.session.flash(temp_file + " -> Ce fichier ne semble pas être un tarif IMH", 'danger')
return HTTPFound(location=url)
# import pdb;pdb.set_trace()
for nsheet in range(book.nsheets):
# pour chaque feuille dans le tableau XLS
sh = book.sheet_by_index(nsheet)
libCol, prixCol, unitCol = 1, 5, 2
if nsheet > 73:
libCol, prixCol, unitCol = 2, 4, 3
for rx in range(sh.nrows):
ref = ""
if sh.cell_type(rx, 0) != 2:
ref = sh.cell_value(rx, 0).strip()
# ligne ayant un ref de tarifs ?
if len(ref) >= 8 and len(ref) < 15 and (ref[2] == '-' or ref[3] == '-'):
new_values = {}
new_values['groupe'] = groupe
new_values['ref'] = ref
if ref[2] == '-':
new_values['famille'] = ref[0:2]
else:
new_values['famille'] = ref[0:3]
if '\n' in sh.cell_value(rx, libCol) and nsheet < 73:
libelleSP = sh.cell_value(rx, libCol).split('\n') # split string with \n as separator if it exists
if libelleSP[1][0] == '(':
libelle = ' '.join(libelleSP[2:]) # if the first character of the second elt is '(' then we remove it
else:
libelle = ' '.join(libelleSP[1:])
else:
libelle = sh.cell_value(rx, libCol)
if len(libelle) > 400:
new_values['libelle'] = 'DATA TOO LONG ! SEE THE ADMIN FOR FURTHER INFOS'
else:
new_values['libelle'] = libelle
unit = sh.cell_value(rx, unitCol)
if unit == 'DEVIS' or 'FORFAIT URGENCE' in unit:
new_values['prixht'] = 0
else:
if sh.cell_type(rx, prixCol) != 2:
new_values['prixht'] = 0
else:
new_values['prixht'] = sh.cell_value(rx, prixCol)
# col Unité renseigné ?
if 'FORFAIT URGENCE' in unit:
unit = 'F. URG.'
new_values['unite'] = unit
update_tarif(request, '0', new_values)
request.session.flash("Le fichier PDF a été importé avec succès.", 'success')