Commit d21485a7 authored by Gabriel Detraz's avatar Gabriel Detraz

Ajoute un menu pour gérer les sacs

parent 1d1424a0
......@@ -17,7 +17,10 @@
<th>Prix unitaire</th>
<th>Quantite</th>
<th>Date de livraison</th>
<th>Livre</th>
<th>Livré</th>
<th>Sac à disposition</th>
<th>Gérer les sacs</th>
<th></th>
</tr>
</thead>
{% for form in controlform.forms %}
......@@ -29,6 +32,9 @@
<td>{{ form.instance.quantite }}</td>
<td>{{ form.instance.date }}</td>
<td>{{ form.livre }}</td>
<td>{{ form.instance.user.sac_consignes }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-sac' form.instance.user.id %}"><i class="glyphicon glyphicon-plus"></i> Ajouter</a></td>
<td> <a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:del-sac' form.instance.user.id %}"><i class="glyphicon glyphicon-minus"></i> Retirer</a></td>
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
......
......@@ -20,6 +20,8 @@ urlpatterns = [
url(r'^add_article/$', views.add_article, name='add-article'),
url(r'^edit_article/(?P<articleid>[0-9]+)$', views.edit_article, name='edit-article'),
url(r'^del_article/$', views.del_article, name='del-article'),
url(r'^add_sac/(?P<userid>[0-9]+)$', views.add_sac, name='add-sac'),
url(r'^del_sac/(?P<userid>[0-9]+)$', views.del_sac, name='del-sac'),
url(r'^control/$', views.control, name='control'),
url(r'^index_article/$', views.index_article, name='index-article'),
url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', views.history, name='history'),
......
......@@ -10,6 +10,7 @@ from django.db import IntegrityError
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth.decorators import login_required, permission_required
from django.http import HttpResponseRedirect
from django.db import transaction
from reversion import revisions as reversion
......@@ -288,7 +289,7 @@ def add_article(request):
def edit_article(request, articleid):
try:
article_instance = Panier.objects.get(pk=articleid)
except Article.DoesNotExist:
except Panier.DoesNotExist:
messages.error(request, u"Entrée inexistante" )
return redirect("/panier/index_article/")
article = PanierForm(request.POST or None, instance=article_instance)
......@@ -326,6 +327,43 @@ def control(request):
return redirect("/panier/")
return render(request, 'panier/control.html', {'controlform': controlform})
@login_required
@permission_required('bureau')
def add_sac(request, userid):
try:
user_instance = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, u"User inexistante" )
try:
article_instance = Panier.objects.get(nom="Sac")
except Panier.DoesNotExist:
messages.error(request, u"Merci de créer une entrée Sac" )
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
user_instance.sac_consignes += 1
user_instance.save()
messages.success(request, u"Sac ajouté à %s (dispose actuellement de %s sacs)" % (user_instance.get_full_name(), user_instance.sac_consignes) )
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
@login_required
@permission_required('bureau')
def del_sac(request, userid):
try:
user_instance = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, u"User inexistante" )
try:
article_instance = Panier.objects.get(nom="Sac")
except Panier.DoesNotExist:
messages.error(request, u"Merci de créer une entrée Sac" )
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
if user_instance.sac_consignes > 0:
user_instance.sac_consignes -= 1
user_instance.save()
messages.success(request, u"Sac retiré à %s (dispose actuellement de %s sacs)" % (user_instance.get_full_name(), user_instance.sac_consignes) )
else:
messages.error(request, u"Nombre de sac nul !" )
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
@login_required
def history(request, object, id):
if object == 'credit':
......@@ -412,7 +450,7 @@ def index(request):
solde_total = sum(us.solde() for us in User.objects.all())
user_total = len(User.objects.filter(state=0))
user_ens = len(User.objects.filter(state=0).filter(is_ens=True))
solde_moyen = solde_total/user_total
solde_moyen = round(solde_total/user_total, 2)
commandes_total = len(Commande.objects.all())
next_livraison = Livraison.objects.order_by('date').filter(date__gt=timezone.now())[0]
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'management_view': management_view, 'credit_list': credit_list, 'solde_total': solde_total, 'user_total': user_total, 'user_ens': user_ens, 'solde_moyen': solde_moyen, 'commandes_total': commandes_total, 'next_livraison': next_livraison})
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0005_auto_20160907_2256'),
]
operations = [
migrations.AddField(
model_name='user',
name='sac_consignes',
field=models.IntegerField(default=0),
),
]
......@@ -82,6 +82,7 @@ class User(AbstractBaseUser):
is_ens = models.BooleanField(default=True)
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
registered = models.DateTimeField(auto_now_add=True)
sac_consignes = models.IntegerField(default=0)
USERNAME_FIELD = 'pseudo'
REQUIRED_FIELDS = ['name', 'surname', 'email', 'telephone']
......@@ -153,7 +154,7 @@ class User(AbstractBaseUser):
def solde(self):
""" Renvoie le solde dynamiquement"""
credit = sum(credit.montant for credit in Credit.objects.filter(user=self) if credit.validite)
debit = sum(commande.prix_unitaire*commande.quantite for commande in Commande.objects.filter(user=self))
debit = sum(commande.prix_unitaire*commande.quantite for commande in Commande.objects.filter(user=self)) + self.sac_consignes
return credit-debit
def __str__(self):
......
......@@ -58,6 +58,8 @@
{% endif %}
</tr>
<tr>
<th>Sac consigné</th>
<td>{{ user.sac_consignes }}</td>
<th>Commentaire</th>
<td>{{ user.comment }}</td>
</tr>
......@@ -66,6 +68,8 @@
<h2>Commandes et crédits</h2>
{% if is_bureau %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-credit' user.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Enregistrer un crédit</a>{% endif %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:new-commande' user.id %}"><i class="glyphicon glyphicon-shopping-cart"></i> Nouvelle commande</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-sac' user.id %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un sac consigné</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:del-sac' user.id %}"><i class="glyphicon glyphicon-minus"></i> Retirer un sac consigné</a>
<br/>
{% include "panier/aff_paniers.html" %}
......
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