Commit c7531813 authored by Gabriel Detraz's avatar Gabriel Detraz

Creation d'une vue pour effectuer les adhesions/readhesions, utilise la nouvelle fonction lc_ldap

parent df589d0b
......@@ -105,3 +105,7 @@ class VenteForm(forms.Form):
articles = forms.MultipleChoiceField(label=u'Articles disponibles', choices=tuple((a,b) for b, a in factures.ITEMS.items()), required=True)
mode = forms.ChoiceField(label=u'Mode de réglement', choices=tuple(factures.VENTE.items()), widget=forms.RadioSelect(), required=True)
commentaire = forms.CharField(label=u'Commentaire', max_length=255, required=False)
class AdhesionForm(forms.Form):
nbrmois = forms.IntegerField(label=u'Nombre de mois de connexion, entre 0 et 12, 0 pour une adhésion seule', min_value=0, max_value=12, required=True)
mode = forms.ChoiceField(label=u'Mode de réglement', choices=tuple(factures.VENTE.items()), widget=forms.RadioSelect(), required=True)
{% extends "template.html" %}
{% block title %} Adhésion et connexion {% endblock %}
{% block h1 %} Prolonger l'adhésion et/ou la connexion {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Prolonger la connexion d'un adhérent, effectue la réadhésion si necessaire</h2>
<div class="row">
<div class="six columns{% if form.nbrmois.errors %} error{% endif %}">
{{ form.nbrmois.label_tag}}
{{ form.nbrmois }}
{{ form.nbrmois.errors }}
</div>
</div>
<div class="row">
<div class="six columns{% if form.mode.errors %} error{% endif %}">
{{ form.mode.label_tag}}
{{ form.mode }}
{{ form.mode.errors }}
</div>
</div>
{% if confirm %}
<h2>Récapitulatif</h2>
<div>Une prolongation de la connexion de {{ nbrmois }} mois va être effectuée</div>
<div>Une facture de {{ prix }} € va être crée, elle comprend la connexion {% if readhesion %} et la réadhésion (10 €){% endif %}</div>
{% endif %}
<footer>
<a href="{% if ptype == "club" %} {% url 'compte:afficher_club' ide %} {% else %} {% url 'compte:afficher' ide %} {% endif %}" class="button-cancel">Retour à mon compte</a>
{% if confirm %}
<input type="submit" value="Valider définitivement">
<input type="hidden" value=1 name="confirm" />
{% else %}
<input type="submit" value="Valider">
{% endif %}
</footer>
</form>
{% endblock %}
......@@ -30,6 +30,11 @@
</span>
(<a href="{% url 'factures:index' %}">détails</a>)
</div>
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:adhesion' 'adh' luser.aid.0 %}">Prolonger l'adhesion/connexion</a>
</div>
{% endif %}
</div>
<h2>Mes informations personnelles</h2>
......
......@@ -30,6 +30,11 @@
</span>
(<a href="{% url 'factures:index' %}">détails</a>)
</div>
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:adhesion' 'adh' luser.aid.0 %}">Prolonger l'adhesion/connexion</a>
</div>
{% endif %}
</div>
<h2>Informations personnelles</h2>
......
......@@ -25,4 +25,6 @@ views.delete_alias, name='delete_alias'),
url('^solde/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.solde, name='solde'),
url('^vente/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.vente, name='vente'),
url('^vente/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.vente, name='vente'),
url('^adhesion/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.adhesion, name='adhesion'),
url('^adhesion/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.adhesion, name='adhesion'),
)
......@@ -19,14 +19,16 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.views.generic import View
import datetime
from passlib.apps import ldap_context
import lc_ldap.crans_utils
from intranet import settings
from gestion.config import factures
from gestion.config import factures, cotisation
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm
from django.forms.util import ErrorList
def is_cableur(user):
......@@ -435,3 +437,83 @@ class VenteView(CableurOrSelfMixin, View):
vente = VenteView.as_view()
class AdhesionView(CableurOrSelfMixin, View):
"""
Classe de base pour l'adhésion
"""
template_name = "compte/adhesion.html"
def get(self, request, uid, ptype, *args, **kwargs):
if ptype == 'club':
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % uid)[0]
else:
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % uid)[0]
form = AdhesionForm()
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, *args, **kwargs):
def action(nbrmois, luser, ptype):
# Détermine en fonction du nombre de mois si l'adhésion va étre faite et calcul le prix
readhesion = False
prix = min(nbrmois * cotisation.contribution, cotisation.plafond_contribution)
now = lc_ldap.crans_utils.localized_datetime()
try:
delta = luser.fin_adhesion().value - now
delta = delta.days
# Si il n'y a pas de fin adh, on renvoie 0
except AttributeError:
delta = 0
if delta < cotisation.delai_readh_jour:
prix += cotisation.cotisation
readhesion = True
# Pour les clubs, c'est gratuit
if ptype == 'club':
prix = 0
return prix, readhesion
# On traite le post
form = AdhesionForm(request.POST)
if ptype == 'club':
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % uid, mode='w')[0]
else:
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % uid)[0]
if form.is_valid():
#EN 2 etapes, on renvoie
if 'confirm' in request.POST.keys():
mois = form.cleaned_data['nbrmois']
prix, readhesion = action(mois, luser, ptype)
fact_cotis = cotisation.dico_cotis(mois)
fact = {
'modePaiement': [form.cleaned_data['mode']],
'article': [u'%s~~%s~~%s~~%s' % (fact_cotis['code'], fact_cotis['designation'], fact_cotis['nombre'], fact_cotis['pu'])],
}
# Si la fonct d readhésion a repondu True, on réadhère aussi
if readhesion:
if ptype == 'club':
dico_adh = cotisation.dico_adh_club
else:
dico_adh = cotisation.dico_adh
fact['article'].append(u'%s~~%s~~%s~~%s' % (dico_adh['code'], dico_adh['designation'], dico_adh['nombre'], dico_adh['pu']))
with conn_pool.get_conn(request.user).newFacture(luser.dn, fact) as facture:
facture.adhesion_connexion()
fid = unicode(facture['fid'][0])
messages.success(request, u"""Vente effectuée, fid=%s (à conserver)""" % (fid))
return redirect_home(uid, ptype)
else:
mois = form.cleaned_data['nbrmois']
prix, readhesion = action(mois, luser, ptype)
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid, 'confirm': True, 'prix': prix, 'readhesion': readhesion, 'nbrmois': mois})
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
@method_decorator(login_required)
def dispatch(self, request, uid, ptype, *args, **kwargs):
if not is_cableur(request.user):
messages.error(request, "Accès interdits, droits insuffisants")
return redirect(settings.LOGIN_URL)
return super(AdhesionView, self).dispatch(request, uid, ptype, *args, **kwargs)
adhesion = AdhesionView.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