scripts/intranet/modules/factures/main.py
bos 5d71550f6b Commit massif sur l'intranet
darcs-hash:20070602131029-c992d-820d228ff611f44b2a1fcb185633a65d865baad2.gz
2007-06-02 15:10:29 +02:00

123 lines
4.6 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
from ClassesIntranet.ModuleBase import ModuleBase
class main(ModuleBase):
def title(self):
return "Factures"
def category(self):
return "Services"
def icon(self):
return "icon.png"
_club = True
def index(self, message = '', error = ''):
adh = cherrypy.session['LDAP'].getProprio(cherrypy.session['uid'])
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, page = 1, items_per_page = 20):
adh = cherrypy.session['LDAP'].getProprio(cherrypy.session['uid'])
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)
histLst.reverse()
page = int(page)
items_per_page = int(items_per_page)
if page == 1:
prevPage = None
else:
prevPage = page - 1
if page * items_per_page >= histLst.__len__():
nextPage = None
else:
nextPage = page + 1
offset = items_per_page * ( page - 1)
return {
'template' :'factures-historique',
'values' :{
'liste':lst,
'historic_items':histLst[offset:offset + items_per_page],
'nextPage':nextPage,
'prevPage':prevPage
},
'stylesheets' :['cransFactures.css'],
'scripts' :[],
}
historique.exposed = True
def delFacture(self, no):
try:
# trrouver la factures
fact = cherrypy.session['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