scripts/intranet/pages/factures.py
gdetrez ffc73b0296 annulation d'une facture non paye
darcs-hash:20061025182958-f46e9-c88fbf735adede3d119ff412ccd27aafe7131dae.gz
2006-10-25 20:29:58 +02:00

96 lines
4 KiB
Python
Executable file

#! /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: #
# #
# 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(useSandbox = cherrypy.config.get("paypal.useSandbox", False),
businessMail = cherrypy.config.get("paypal.businessAdress", "paypal@crans.org"),
return_page = "https://intranet.crans.org/monCompte/paypalReturn",
cancel_return_page = "https://intranet.crans.org/monCompte/paypalCancel",
)
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' : ',1)[1].startswith(u'credit') or x.split(u' : ',1)[1].startswith(u'debit') ]
histLst = []
for anItem in lst:
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
def delFacture(self, no):
try:
# trrouver la factures
fact = self.__ldap.search('fid=' + no, 'w')['facture'][0]
#verifier qu'elle appartient bien a l'adherent
if not fact.proprietaire().mail() == cherrypy.session['uid']:
raise Exception, "Impossible de supprimer cette facture"
# la supprimer
fact.delete()
except Exception, e:
cherrypy.log(str(e), "FACTURES", 1)
return self.index()
delFacture.exposed = True