diff --git a/mondumas/views/parametres.py b/mondumas/views/parametres.py index e4e67ac..8f39785 100644 --- a/mondumas/views/parametres.py +++ b/mondumas/views/parametres.py @@ -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 = 'M²' + 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 = '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) + request.session.flash("Le fichier PDF a été importé avec succès.", 'success') return HTTPFound(location=url) diff --git a/setup.py b/setup.py index 54047b2..ef7d666 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ requires = [ 'pyramid_layout', 'pyramid_mailer', 'pyramid_tm', - 'SQLAlchemy', + 'SQLAlchemy == 1.2.19', 'transaction', 'zope.sqlalchemy == 1.1', 'waitress',