Passage à lc_ldap et modernisation

This commit is contained in:
Gabriel Detraz 2015-08-23 20:05:03 +02:00
parent 8c503584f9
commit 13d8829e0d

View file

@ -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 <blockelet@crans.org>
#
# 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:
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:
cprint('Debit total pour ' + adherent.Nom() + ' : ' + str(adhdebit) + ' euros', 'rouge')
cprint('Credit total pour ' + adherent.Nom() + ' : ' + str(adhcredit) + ' euros', 'vert')
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: