ajout import tarif maif

This commit is contained in:
cthienan
2021-07-22 14:42:04 +02:00
parent 7a706ba9f2
commit 1d1b8b29a7
2 changed files with 68 additions and 33 deletions

View File

@@ -794,39 +794,74 @@ def tarifs_import(request):
# readxl returns a pylightxl database that holds all worksheets and its data
book = xlrd.open_workbook(temp_file)
# lire la 1ère feuille et contôler que c'est fichier AXA
sh = book.sheet_by_index(0)
ctl_cellA1 = sh.cell_value(rowx=0, colx=0)
if ctl_cellA1 != 'PEN_2_MISEEN':
request.session.flash(temp_file + " -> Ce fichier ne semble pas être un tarif AXA", '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)
for rx in range(sh.nrows):
ref = sh.cell_value(rx, 0).strip()
# ligne ayant un ref de tarifs ?
if len(ref) >= 12 and len(ref) < 15 and ref[3]=='_':
new_values = {}
new_values['groupe'] = groupe
new_values['ref'] = ref
new_values['famille'] = ref[0:3]
libelle = sh.cell_value(rx, 1)
new_values['libelle'] = libelle.replace(' F+P M²', '').replace(' F+P U', '')
new_values['prixht'] = sh.cell_value(rx, 5)
# col Unité renseigné ?
if len(sh.cell_value(rx, 3)) > 0:
unite = sh.cell_value(rx, 3)
else:
if sh.cell_value(rx, 1).find(' M2'):
unite = ''
if groupe == "AXA":
# lire la 1ère feuille et contôler que c'est fichier AXA
sh = book.sheet_by_index(0)
ctl_cellA1 = sh.cell_value(rowx=0, colx=0)
if ctl_cellA1 != 'PEN_2_MISEEN':
request.session.flash(temp_file + " -> Ce fichier ne semble pas être un tarif AXA", '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)
for rx in range(sh.nrows):
ref = sh.cell_value(rx, 0).strip()
# ligne ayant un ref de tarifs ?
if len(ref) >= 12 and len(ref) < 15 and ref[3]=='_':
new_values = {}
new_values['groupe'] = groupe
new_values['ref'] = ref
new_values['famille'] = ref[0:3]
libelle = sh.cell_value(rx, 1)
new_values['libelle'] = libelle.replace(' F+P M²', '').replace(' F+P U', '')
new_values['prixht'] = sh.cell_value(rx, 5)
# col Unité renseigné ?
if len(sh.cell_value(rx, 3)) > 0:
unite = sh.cell_value(rx, 3)
else:
unite = 'U'
new_values['unite'] = unite
update_tarif(request, '0', new_values)
if sh.cell_value(rx, 1).find(' M2'):
unite = ''
else:
unite = 'U'
new_values['unite'] = unite
update_tarif(request, '0', new_values)
elif groupe == "MAIF":
# lire la 1ère feuille et contôler que c'est fichier MAIF
sh = book.sheet_by_index(0)
ctl_cellA6 = sh.cell_value(rowx=5, colx=0)
if ctl_cellA6 != 'PEN_01':
request.session.flash(temp_file + " -> Ce fichier ne semble pas être un tarif MAIF", '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)
for rx in range(sh.nrows):
ref = sh.cell_value(rx, 0).strip()
# ligne ayant un ref de tarifs ?
if len(ref) >= 6 and len(ref) < 15 and ref[3]=='_':
new_values = {}
new_values['groupe'] = groupe
new_values['ref'] = ref
new_values['famille'] = ref[0:3]
libelle = sh.cell_value(rx, 1)
new_values['libelle'] = libelle.replace(' F+P M²', '').replace(' F+P U', '')
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:
unite = sh.cell_value(rx, 3)
else:
if sh.cell_value(rx, 1).find(' m2'):
unite = ''
else:
unite = 'U'
new_values['unite'] = unite
update_tarif(request, '0', new_values)
request.session.flash("Le fichier PDF a été importé avec succès.", 'success')
return HTTPFound(location=url)