diff --git a/admin/total_impression.py b/admin/total_impression.py index 8a54074c..58f32cb8 100755 --- a/admin/total_impression.py +++ b/admin/total_impression.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/bin/bash /usr/scripts/python.sh # -*- mode: python; coding: utf-8 -*- # # total_impression.py @@ -6,6 +6,7 @@ # # Copyright (C) 2007 Michel Blockelet # +# Revu et corrigé en 2015 par Gabriel Détraz # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -32,14 +33,11 @@ Options : Les dates doivent etre de la forme jj/mm/aaaa.""" import sys -sys.path.append("/usr/scripts/gestion/") -from ldap_crans import crans_ldap -from config import ann_scol -from affich_tools import cprint +from lc_ldap import shortcuts +from gestion.affich_tools import cprint import time -db = crans_ldap() -date_debut_ann_scol = time.mktime((ann_scol, 8, 1, 0, 0, 0, 0, 0, 0)) +ldap = shortcuts.lc_ldap_admin() def datestrtoint(strdate): u""" Convertit une date en entier. """ @@ -52,7 +50,7 @@ def soldes_adherent(dlinf, dlsup, adherent, verbose): totaldebit = 0 totalcredit = 0 - for hist in adherent.historique(): + for hist in adherent['historique']: sep = ' ' champ = hist.replace(',', '').replace(': ', '').split(sep) if datestrtoint(champ[0]) >= dlinf and (dlsup == 0 or datestrtoint(champ[0]) <= dlsup): @@ -112,19 +110,23 @@ def calcul_soldes(): totaldebit = 0 totalcredit = 0 - liste = db.search("login=*")['adherent'] + liste = ldap.search(u"uid=*",sizelimit=10000) for adherent in liste: - adhdebit, adhcredit = soldes_adherent(dlinf, dlsup, adherent, verbose) - if adhdebit + adhcredit > 0 and adhdebit + adhcredit < 1000000: # On evite Toto Passoir - if verbose >= 2: - cprint('-' * 40, 'cyan') - if verbose >= 1: - cprint('Debit total pour ' + adherent.Nom() + ' : ' + str(adhdebit) + ' euros', 'rouge') - cprint('Credit total pour ' + adherent.Nom() + ' : ' + str(adhcredit) + ' euros', 'vert') - cprint('=' * 40, 'bleu') - totaldebit += adhdebit - totalcredit += adhcredit + try: + adhdebit, adhcredit = soldes_adherent(dlinf, dlsup, adherent, verbose) + if adhdebit + adhcredit > 0 and adhdebit + adhcredit < 1000000: # On evite Toto Passoir + if verbose >= 2: + cprint('-' * 40, 'cyan') + if verbose >= 1: + name = unicode(adherent['prenom'][0]) + u" " + unicode(adherent['nom'][0]) + cprint(u'Debit total pour ' + name + u' : ' + unicode(adhdebit) + u' euros', 'rouge') + cprint(u'Credit total pour ' + name + u' : ' + unicode(adhcredit) + u' euros', 'vert') + cprint('=' * 40, 'bleu') + totaldebit += adhdebit + totalcredit += adhcredit + except KeyError: + pass if verbose >= 1: cprint('=' * 80, 'bleu') if dlinf == 0: