Commit 1642e80d authored by Gabriel Detraz's avatar Gabriel Detraz

Création d'une vue pour la vente (factures) séparation avec solde

parent a67ad011
......@@ -96,7 +96,12 @@ class BasePassForm(forms.Form):
class PassForm(BasePassForm):
passwdexists = forms.CharField(label=u'Ancien mot de passe', max_length=255, widget=widgets.PasswordInput, required=True)
class FactureForm(forms.Form):
class SoldeForm(forms.Form):
montant = forms.DecimalField(label=u'Montant à ajouter ou supprimer', required=True)
mode = forms.ChoiceField(choices=tuple(factures.SOLDE.items()), widget=forms.RadioSelect(), required=True)
mode = forms.ChoiceField(label=u'Mode de réglement', choices=tuple(factures.SOLDE.items()), widget=forms.RadioSelect(), required=True)
commentaire = forms.CharField(label=u'Commentaire', max_length=255, required=False)
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)
......@@ -83,12 +83,15 @@
</div>
<div class="row">
<div class="six columns">
<div class="four columns">
<a class="button" href="{% url 'compte:chgpass' 'adh' luser.aid.0 %}">Changer mon mot de passe</a>
</div>
{% if cablage %}
<div class="six columns">
<a class="button" href="{% url 'compte:facture' 'adh' luser.aid.0 %}">Vendre un article ou modifier le solde</a>
<div class="four columns">
<a class="button" href="{% url 'compte:solde' 'adh' luser.aid.0 %}">Modifier le solde</a>
</div>
<div class="four columns">
<a class="button" href="{% url 'compte:vente' 'adh' luser.aid.0 %}">Vendre un article</a>
</div>
{% endif %}
</div>
......
......@@ -52,7 +52,17 @@
</div>
<div class="row">
<a class="button" href="{% url 'compte:chgpass' 'club' luser.cid.0 %}">Changer mon mot de passe</a>
<div class="four columns">
<a class="button" href="{% url 'compte:chgpass' 'club' luser.cid.0 %}">Changer mon mot de passe</a>
</div>
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:solde' 'club' luser.cid.0 %}">Modifier le solde</a>
</div>
<div class="four columns">
<a class="button" href="{% url 'compte:vente' 'club' luser.cid.0 %}">Vendre un article</a>
</div>
{% endif %}
</div>
<h2>Mail</h2>
......
{% extends "template.html" %}
{% block title %} Factures et solde {% endblock %}
{% block h1 %} Créer une facture ou modifier le solde {% endblock %}
{% block title %} Solde {% endblock %}
{% block h1 %} Modifier le solde {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
......
{% extends "template.html" %}
{% block title %} Factures {% endblock %}
{% block h1 %} Vente {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Vendre un article</h2>
<div class="row">
<div class="six columns{% if form.articles.errors %} error{% endif %}">
{{ form.articles.label_tag}}
{{ form.articles }}
{{ form.articles.errors }}
</div>
<div class="six columns{% if form.commentaire.errors %} error{% endif %}">
{{ form.commentaire.label_tag}}
{{ form.commentaire }}
{{ form.commentaire.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>
<footer>
<a href="{% if ptype == "club" %} {% url 'compte:afficher_club' ide %} {% else %} {% url 'compte:afficher' ide %} {% endif %}" class="button-cancel">Retour à mon compte</a>
<input type="submit" value="Enregistrer">
</footer>
</form>
{% endblock %}
......@@ -21,6 +21,8 @@ urlpatterns = patterns('',
views.delete_alias, name='delete_alias'),
url('^delete_alias/(?P<uid>[0-9]+)/(?P<ptype>club)/(?P<alias_id>[0-9]+)/$',
views.delete_alias, name='delete_alias'),
url('^facture/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.facture, name='facture'),
url('^facture/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.facture, name='facture'),
url('^solde/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.solde, name='solde'),
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'),
)
......@@ -2,6 +2,7 @@
# Récriture de l'app compte
# Enrichissement de celle-ci.
# Gabriel Détraz detraz@crans.org
# Charlie Jacomme jacomme@crans.org
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
......@@ -23,7 +24,7 @@ import lc_ldap.crans_utils
from intranet import settings
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, FactureForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm
from django.forms.util import ErrorList
def is_cableur(user):
......@@ -343,21 +344,21 @@ alias = AliasView.as_view()
class FactureView(CableurOrSelfMixin, View):
class SoldeView(CableurOrSelfMixin, View):
"""
Classe de base pour les modifications de solde
"""
template_name = "compte/facture.html"
template_name = "compte/solde.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 = FactureForm()
form = SoldeForm()
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, *args, **kwargs):
form = FactureForm(request.POST)
form = SoldeForm(request.POST)
if ptype == 'club':
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % uid, mode='w')[0]
else:
......@@ -376,7 +377,56 @@ class FactureView(CableurOrSelfMixin, View):
if not is_cableur(request.user):
messages.error(request, "Accès interdits, droits insuffisants")
return redirect(settings.LOGIN_URL)
return super(FactureView, self).dispatch(request, uid, ptype, *args, **kwargs)
return super(SoldeView, self).dispatch(request, uid, ptype, *args, **kwargs)
facture = FactureView.as_view()
solde = SoldeView.as_view()
class VenteView(CableurOrSelfMixin, View):
"""
Classe de base pour la vente d'objets
"""
template_name = "compte/vente.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 = VenteForm()
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, *args, **kwargs):
form = VenteForm(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, mode='w')[0]
if form.is_valid():
# Boucle sur les différents articles
for art in form.cleaned_data['articles']:
# On retrouve le code correspondant
for choice in form.fields['articles'].choices:
if unicode(choice[0]) == unicode(art):
code = choice[1]
break
art = eval(art)
fact = {
'modePaiement': [form.cleaned_data['mode']],
'article': [u'%s~~%s~~1~~%s' % (code, art['designation'] + " " + form.cleaned_data['commentaire'],art['pu'])],
}
with conn_pool.get_conn(request.user).newFacture(luser.dn, fact) as facture:
facture.crediter()
messages.success(request, u"""Vente effectuée""")
return redirect_home(uid, ptype)
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(VenteView, self).dispatch(request, uid, ptype, *args, **kwargs)
vente = VenteView.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