#! /usr/bin/env python # -*- coding: iso-8859-15 -*- # ##################################################################################################### # # Factures # # ##################################################################################################### # # Description: # # Affiche la liste des factures et l'historique de débits/crédits de l'adhérent. # # Informations: # # Pas d'AJAX ici en principe # # Pages: # # index:liste des factures # # historique: historique des débits/crédits # # ##################################################################################################### # import cherrypy, sys, os, datetime class root: __ldap = None def __init__(self): self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"] def index(self, message = '', error = ''): adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] t = {} t['message'] = message t['error'] = error ############## liste des factures ############## listeFactures = [] for f in adh.factures(): facture = {} facture['no'] = f.numero() facture['intitule'] = f.articles()[0]['designation'] facture['details'] = [ { 'intitule':art['designation'], 'quantite':art['nombre'], 'prixUnitaire':art['pu'], 'prixTotal':art['pu']*art['nombre'], } for art in f.articles()] facture['montant'] = f.total() facture['paypal'] = f.urlPaypal() facture['payee'] = f.recuPaiement() listeFactures.append(facture) t['listeFactures'] = listeFactures return { 'template' :'factures', 'values' :t, 'stylesheets' :['cransFactures.css'], 'scripts' :[], } index.exposed = True def historique(self): adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] lst = [ x for x in adh.historique() if x.split(u' : ',2)[1].startswith(u'credit') or x.split(u' : ',2)[1].startswith(u'debit') ] histLst = [] for anItem in lst: #11/06/2006 01:40, gdetrez : credit 10.0 Euros [Facture n°1 : Impression] aLine = {} aLine["date"] = anItem.split(u",")[0] aLine["type"] = anItem.split(u' : ',2)[1].split(u' ')[0] aLine["montant"] = anItem.split(u' : ',2)[1].split(u' ')[1] try: aLine["intitule"] = anItem.split(u'[')[1].split(u']')[0] except Exception: aLine["intitule"] = "" histLst.append(aLine) return { 'template' :'factures-historique', 'values' :{'liste':lst, 'historic_items':histLst}, 'stylesheets' :['cransFactures.css'], 'scripts' :[], } historique.exposed = True