100 lines
3.9 KiB
Python
Executable file
100 lines
3.9 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 icon(self):
|
|
return "icon.png"
|
|
|
|
|
|
def index(self, message = '', error = ''):
|
|
adh = cherrypy.session['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 = cherrypy.session['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 = 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
|