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