Commit aa1f3101 authored by Gabriel Detraz's avatar Gabriel Detraz

Redirige vers la bonne liste des factures (cf voir dans mon compte)

parent 77676c09
......@@ -41,7 +41,7 @@
{% endif %}
Jusqu'au {{ luser.fin_connexion.value }}
</span>
(<a href="{% url 'factures:index' %}">détails</a>)
(<a href="{% url 'factures:liste' 'adh' luser.aid.0 %}">détails</a>)
</div>
{% if cablage %}
<div class="four columns">
......
......@@ -4,5 +4,9 @@ import views
urlpatterns = patterns('',
url('^$', views.index, name='index'),
url('(?P<fid>[0-9]+).pdf', views.facture)
url('^liste/(?P<ptype>club)/(?P<cid>[0-9]+)/$', views.index, name='liste'),
url('^liste/(?P<ptype>adh)/(?P<aid>[0-9]+)/$', views.index, name='liste'),
url('(?P<fid>[0-9]+).pdf', views.facture, name='facture'),
url('^liste/(?P<ptype>adh)/(?P<aid>[0-9]+)/(?P<fid>[0-9]+).pdf/$', views.facture, name='facture'),
url('^liste/(?P<ptype>club)/(?P<cid>[0-9]+)/(?P<fid>[0-9]+).pdf/$', views.facture, name='facture')
)
......@@ -6,6 +6,7 @@ from django.template.loader import render_to_string
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.template import RequestContext
......@@ -17,32 +18,62 @@ import hashlib
import time
from intranet import settings, conn_pool
@login_required
def index(request):
luser = conn_pool.get_user(request.user)
return render(request, 'factures/index.html', {'luser': luser})
@login_required
def facture(request, fid):
luser = conn_pool.get_user(request.user)
f = conn_pool.get_conn(request.user).search(u"fid=%s" % int(fid))
if not f:
return redirect('factures:index')
else:
f = f[0]
if not f.dn in [fac.dn for fac in luser.factures()]:
return redirect('factures:index')
total = 0
for i in range(0,len(f['article'])):
f['article'][i].value['ptotal']=int(f['article'][i]['nombre']) * float(f['article'][i]['pu'])
total += f['article'][i].value['ptotal']
if f.get('recuPaiement', []):
paid = total
else:
paid = 0
(jour, heure) = f['historique'][0].value.split(',')[0].split(" ")
date = u"Le %s à %s" % (jour, heure.replace(":", "h"))
topay = total - paid
# return render(request, 'factures/facture.tex', {'total':total, 'paid':paid, 'topay':total-paid, 'date':f['historique'][0].value.split(',')[0], 'f':f})
return render_tex(request, 'factures/facture.tex', {'total':total, 'paid':paid, 'topay':topay, 'DATE':date, 'f':f, 'fid':fid})
from django.views.generic import View
from intranet.mixins import CableurOrSelfMixin, CableurMixin
class IndexView(CableurOrSelfMixin, View):
"""
Classe de base pour l'index
"""
template_name = "factures/index.html"
def get(self, request, aid, cid, ptype, *args, **kwargs):
if ptype=="adh":
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid)[0]
elif ptype=="club":
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % aid)[0]
return render(request, self.template_name, {'luser': luser})
@method_decorator(login_required)
def dispatch(self, request, aid=None, cid=None, ptype=None, *args, **kwargs):
if not aid and not cid: # Si aid=None, on renvoit celui de l'user
luser = conn_pool.get_user(request.user)
if luser.ldap_name == 'club':
cid = luser['cid'][0]
ptype = 'club'
else:
aid = luser['aid'][0]
ptype = 'adh'
return super(IndexView, self).dispatch(request, aid, cid, ptype, *args, **kwargs)
index = IndexView.as_view()
class FactureView(View):
def get(self, request, fid):
luser = conn_pool.get_user(request.user)
f = conn_pool.get_conn(request.user).search(u"fid=%s" % int(fid))
if not f:
return redirect('factures:index')
else:
f = f[0]
if not f.dn in [fac.dn for fac in luser.factures()] and not request.user.has_perm('auth.crans_cableur'):
return redirect('factures:index')
total = 0
for i in range(0,len(f['article'])):
f['article'][i].value['ptotal']=int(f['article'][i]['nombre']) * float(f['article'][i]['pu'])
total += f['article'][i].value['ptotal']
if f.get('recuPaiement', []):
paid = total
else:
paid = 0
(jour, heure) = f['historique'][0].value.split(',')[0].split(" ")
date = u"Le %s à %s" % (jour, heure.replace(":", "h"))
topay = total - paid
return render_tex(request, 'factures/facture.tex', {'total':total, 'paid':paid, 'topay':topay, 'DATE':date, 'f':f, 'fid':fid})
facture = FactureView.as_view()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment