Commit 16f92d3a authored by Gabriel Detraz's avatar Gabriel Detraz

Systeme de commande fonctionnel

parent 72a43bdc
...@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/ ...@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, MINIMUM_LEVEL, SITE_NAME
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<thead> <thead>
<tr> <tr>
<th>Date</th> <th>Date</th>
<th>Cableur</th> <th>Action effectuee par</th>
<th>Commentaire</th> <th>Commentaire</th>
</tr> </tr>
</thead> </thead>
......
...@@ -9,7 +9,7 @@ class PanierAdmin(VersionAdmin): ...@@ -9,7 +9,7 @@ class PanierAdmin(VersionAdmin):
list_display = ('prix','nom') list_display = ('prix','nom')
class CommandeAdmin(admin.ModelAdmin): class CommandeAdmin(admin.ModelAdmin):
list_display = ('user', 'quantite', 'prix', 'livre', 'date') list_display = ('user', 'quantite', 'prix_unitaire', 'nom', 'livre', 'date')
class CreditAdmin(VersionAdmin): class CreditAdmin(VersionAdmin):
list_display = ('user','montant','moyen','validite') list_display = ('user','montant','moyen','validite')
......
...@@ -4,14 +4,36 @@ from django import forms ...@@ -4,14 +4,36 @@ from django import forms
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from .models import Panier, Paiement, Commande, Credit, Livraison from .models import Panier, Paiement, Commande, Credit, Livraison
class NewCommandeForm(ModelForm):
class Meta:
model = Commande
fields = ['quantite','date']
class BaseEditCommandeForm(NewCommandeForm):
class Meta(NewCommandeForm.Meta):
fields = ['quantite','date']
class FullEditCommandeForm(NewCommandeForm):
class Meta(NewCommandeForm.Meta):
fields = '__all__'
class SelectArticleForm(ModelForm):
article = forms.ModelChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement")
class Meta:
exclude = ['nom','prix']
model = Panier
class LivraisonForm(ModelForm): class LivraisonForm(ModelForm):
class Meta: class Meta:
model = Livraison model = Livraison
fields = ['date'] fields = ['date','date_modif']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(LivraisonForm, self).__init__(*args, **kwargs) super(LivraisonForm, self).__init__(*args, **kwargs)
self.fields['date'].label = 'Date de livraison' self.fields['date'].label = 'Date de livraison'
self.fields['date_modif'].label = 'Date limite de modification'
class DelLivraisonForm(ModelForm): class DelLivraisonForm(ModelForm):
date = forms.ModelMultipleChoiceField(queryset=Livraison.objects.all(), label="Date de livraison", widget=forms.CheckboxSelectMultiple) date = forms.ModelMultipleChoiceField(queryset=Livraison.objects.all(), label="Date de livraison", widget=forms.CheckboxSelectMultiple)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0004_remove_panier_quantite'),
]
operations = [
migrations.RenameField(
model_name='commande',
old_name='prix',
new_name='prix_unitaire',
),
migrations.AddField(
model_name='commande',
name='nom',
field=models.CharField(default='Panier', max_length=255),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import datetime
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('panier', '0005_auto_20160905_0207'),
]
operations = [
migrations.AddField(
model_name='livraison',
name='date_modif',
field=models.DateTimeField(default=datetime.datetime(2016, 9, 5, 0, 51, 14, 377006, tzinfo=utc), help_text='%d/%m/%y %H:%M:%S'),
preserve_default=False,
),
]
...@@ -14,11 +14,15 @@ class Panier(models.Model): ...@@ -14,11 +14,15 @@ class Panier(models.Model):
class Commande(models.Model): class Commande(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT) user = models.ForeignKey('users.User', on_delete=models.PROTECT)
nom = models.CharField(max_length=255)
quantite = models.IntegerField() quantite = models.IntegerField()
prix = models.DecimalField(max_digits=5, decimal_places=2) prix_unitaire = models.DecimalField(max_digits=5, decimal_places=2)
livre = models.BooleanField(default=False) livre = models.BooleanField(default=False)
date = models.ForeignKey('Livraison', on_delete=models.PROTECT) date = models.ForeignKey('Livraison', on_delete=models.PROTECT)
def prix(self):
return self.prix_unitaire*self.quantite
class Credit(models.Model): class Credit(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT) user = models.ForeignKey('users.User', on_delete=models.PROTECT)
montant = models.DecimalField(max_digits=5, decimal_places=2) montant = models.DecimalField(max_digits=5, decimal_places=2)
...@@ -26,7 +30,7 @@ class Credit(models.Model): ...@@ -26,7 +30,7 @@ class Credit(models.Model):
validite = models.BooleanField(default=True) validite = models.BooleanField(default=True)
def __str__(self): def __str__(self):
return str(self.montant) + str(self.user) return str(self.montant) + "€ pour " + str(self.user)
class Paiement(models.Model): class Paiement(models.Model):
moyen = models.CharField(max_length=255, unique=True) moyen = models.CharField(max_length=255, unique=True)
...@@ -36,6 +40,7 @@ class Paiement(models.Model): ...@@ -36,6 +40,7 @@ class Paiement(models.Model):
class Livraison(models.Model): class Livraison(models.Model):
date = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S') date = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
date_modif = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
def __str__(self): def __str__(self):
return str(self.date) return str(self.date)
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
<tr> <tr>
<td>{{ article.nom }}</td> <td>{{ article.nom }}</td>
<td>{{ article.prix }}</td> <td>{{ article.prix }}</td>
{% if is_bureau %}
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:edit-article' article.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a> <td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:edit-article' article.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>
<a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'article' article.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td> <a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'article' article.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
<thead> <thead>
<tr> <tr>
<th>Date de livraison</th> <th>Date de livraison</th>
<th>Date limite de modification des commandes</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for livraison in livraison_list %} {% for livraison in livraison_list %}
<tr> <tr>
<td>{{ livraison.date }}</td> <td>{{ livraison.date }}</td>
<td>{{ livraison.date_modif }}</td>
{% if is_bureau %}
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:edit-livraison' livraison.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a> <td><a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:edit-livraison' livraison.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a>
<a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'livraison' livraison.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td> <a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'livraison' livraison.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
...@@ -20,20 +20,38 @@ ...@@ -20,20 +20,38 @@
<tr> <tr>
<th>Nom</th> <th>Nom</th>
<th>Prenom</th> <th>Prenom</th>
<th>Qualité</th>
<th>Quantité</th> <th>Quantité</th>
<th>Prix</th> <th>Prix</th>
<th>Livré</th> <th>Livré</th>
<th>Date de livraison</th> <th>Date de livraison</th>
<th></th>
<th></th>
</tr> </tr>
</thead> </thead>
{% for panier in paniers_list %} {% for panier in paniers_list %}
<tr> <tr>
<td>{{ panier.user.name }}</td> <td>{{ panier.user.name }}</td>
<td>{{ panier.user.surname }}</td> <td>{{ panier.user.surname }}</td>
<td>{{ panier.nom }}</td>
<td>{{ panier.quantite }}</td> <td>{{ panier.quantite }}</td>
<td>{{ panier.prix }}</td> <td>{{ panier.prix }}</td>
<td>{{ panier.livre }}</td> {% if panier.livre %}
<td><font color="green">Oui</font></td>
{% else %}
<td><font color="red">Non</font></td>
{% endif %}
<td>{{ panier.date }}</td> <td>{{ panier.date }}</td>
<td><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioncredit" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Modifier
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editionfacture">
<li><a href="{% url 'panier:edit-commande' panier.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a></li>
<li><a href="{% url 'panier:del-commande' panier.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
</ul></div></td>
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'commande' panier.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
...@@ -73,7 +91,11 @@ ...@@ -73,7 +91,11 @@
<td>{{ credit.user.surname }}</td> <td>{{ credit.user.surname }}</td>
<td>{{ credit.montant }}</td> <td>{{ credit.montant }}</td>
<td>{{ credit.moyen }}</td> <td>{{ credit.moyen }}</td>
<td>{{ credit.validite }}</td> {% if credit.validite %}
<td><font color="green">Oui</font></td>
{% else %}
<td><font color="red">Non</font></td>
{% endif %}
{% if is_bureau %} {% if is_bureau %}
<td><div class="dropdown"> <td><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioncredit" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> <button class="btn btn-default dropdown-toggle" type="button" id="editioncredit" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
{% block content %} {% block content %}
<h2>Liste des types d'articles</h2> <h2>Liste des types d'articles</h2>
{% if is_bureau %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-article' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type d'articles</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-article' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type d'articles</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-article' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types d'articles</a> <a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-article' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types d'articles</a>
{% endif %}
{% include "panier/aff_article.html" with article_list=article_list %} {% include "panier/aff_article.html" with article_list=article_list %}
<br /> <br />
<br /> <br />
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
{% block content %} {% block content %}
<h2>Liste des dates de livraisons</h2> <h2>Liste des dates de livraisons</h2>
{% if is_bureau %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-livraison' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une date de livraison</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-livraison' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une date de livraison</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-livraison' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs dates de livraisons</a> <a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-livraison' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer une ou plusieurs dates de livraisons</a>
{% endif %}
{% include "panier/aff_livraison.html" with livraison_list=livraison_list %} {% include "panier/aff_livraison.html" with livraison_list=livraison_list %}
<br /> <br />
<br /> <br />
......
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
{% block content %} {% block content %}
<h2>Liste des types de paiements</h2> <h2>Liste des types de paiements</h2>
{% if is_bureau %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-paiement' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de paiement</a> <a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-paiement' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type de paiement</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-paiement' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de paiements</a> <a class="btn btn-danger btn-sm" role="button" href="{% url 'panier:del-paiement' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types de paiements</a>
{% endif %}
{% include "panier/aff_paiement.html" with paiement_list=paiement_list %} {% include "panier/aff_paiement.html" with paiement_list=paiement_list %}
<br /> <br />
<br /> <br />
......
{% extends "panier/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Creation et modification de commander{% endblock %}
{% block content %}
{% bootstrap_form_errors article_form %}
{% bootstrap_form_errors commande_form %}
<h2>Commander un panier</h2>
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form article_form %}
{% bootstrap_form commande_form %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<br />
<br />
<br />
{% endblock %}
{% extends "base.html" %} {% extends "base.html" %}
{% block sidebar %} {% block sidebar %}
{% if is_bureau %}
<p><a href="{% url "panier:index-paiement" %}">Liste des moyens de paiement</a></p>
<p><a href="{% url "panier:index-livraison" %}">Liste des dates de livraison</a></p> <p><a href="{% url "panier:index-livraison" %}">Liste des dates de livraison</a></p>
<p><a href="{% url "panier:index-article" %}">Liste des paniers en vente</a></p> <p><a href="{% url "panier:index-article" %}">Liste des paniers en vente</a></p>
{% if is_bureau %}
<p><a href="{% url "panier:index-paiement" %}">Liste des moyens de paiement</a></p>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
...@@ -3,6 +3,9 @@ from django.conf.urls import url ...@@ -3,6 +3,9 @@ from django.conf.urls import url
from . import views from . import views
urlpatterns = [ urlpatterns = [
url(r'^new_commande/(?P<userid>[0-9]+)$', views.new_commande, name='new-commande'),
url(r'^edit_commande/(?P<commandeid>[0-9]+)$', views.edit_commande, name='edit-commande'),
url(r'^del_commande/(?P<commandeid>[0-9]+)$', views.del_commande, name='del-commande'),
url(r'^add_paiement/$', views.add_paiement, name='add-paiement'), url(r'^add_paiement/$', views.add_paiement, name='add-paiement'),
url(r'^edit_paiement/(?P<paiementid>[0-9]+)$', views.edit_paiement, name='edit-paiement'), url(r'^edit_paiement/(?P<paiementid>[0-9]+)$', views.edit_paiement, name='edit-paiement'),
url(r'^del_paiement/$', views.del_paiement, name='del-paiement'), url(r'^del_paiement/$', views.del_paiement, name='del-paiement'),
...@@ -22,6 +25,7 @@ urlpatterns = [ ...@@ -22,6 +25,7 @@ urlpatterns = [
url(r'^history/(?P<object>livraison)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>livraison)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>credit)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>credit)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>article)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>article)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>commande)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]
......
...@@ -15,11 +15,11 @@ from django.db import transaction ...@@ -15,11 +15,11 @@ from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from .models import Panier, Paiement, Commande, Credit, Livraison from .models import Panier, Paiement, Commande, Credit, Livraison
from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, DelLivraisonForm from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, DelLivraisonForm
from .forms import PanierForm, DelPanierForm from .forms import PanierForm, DelPanierForm, SelectArticleForm, BaseEditCommandeForm, NewCommandeForm
from users.views import User from users.views import User
from amap.settings import PAGINATION_NUMBER from amap.settings import MINIMUM_LEVEL, PAGINATION_NUMBER
def form(ctx, template, request): def form(ctx, template, request):
c = ctx c = ctx
...@@ -30,6 +30,77 @@ def form(ctx, template, request): ...@@ -30,6 +30,77 @@ def form(ctx, template, request):
context_instance=RequestContext(request) context_instance=RequestContext(request)
) )
@login_required
def new_commande(request, userid):
try:
user = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, u"Utilisateur inexistant" )
return redirect("/panier/")
if not request.user.has_perms(('bureau',)) and user != request.user:
messages.error(request, "Vous ne pouvez pas commander pour quelqu'un d'autre !")
return redirect("/users/profil/" + str(request.user.id))
commande = Commande(user=user)
commande_form = NewCommandeForm(request.POST or None, instance=commande)
article_form = SelectArticleForm(request.POST or None)
if commande_form.is_valid() and article_form.is_valid():
commande = commande_form.save(commit=False)
prix_unitaire = article_form.cleaned_data['article'].prix
quantite = commande.quantite
if user.solde() - prix_unitaire*quantite < MINIMUM_LEVEL:
messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/users/profil/" + userid)
with transaction.atomic(), reversion.create_revision():
commande.prix_unitaire = article_form.cleaned_data['article'].prix
commande.nom = article_form.cleaned_data['article'].nom
commande.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "La commande est enregistree")
return redirect("/users/profil/" + userid)
return form({'article_form': article_form, 'commande_form': commande_form}, 'panier/new_commande.html', request)
@login_required
def edit_commande(request, commandeid):
try:
commande_instance = Commande.objects.get(pk=commandeid)
except Commande.DoesNotExist:
messages.error(request, u"Entrée inexistante" )
return redirect("/panier/")
if not request.user.has_perms(('bureau',)) and commande_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas commander pour quelqu'un d'autre !")
return redirect("/users/profil/" + str(request.user.id))
if request.user.has_perms(('bureau',)):
commande = BaseEditCommandeForm(request.POST or None, instance=commande_instance)
else:
commande = FullEditCommandeForm(request.POST or None, instance=commande_instance)
if commande.is_valid():
with transaction.atomic(), reversion.create_revision():
commande.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in commande.changed_data))
messages.success(request, "Commande modifiee")
return redirect("/panier/")
return form({'panierform': commande}, 'panier/panier.html', request)
@login_required
def del_commande(request, commandeid):
try:
commande = Commande.objects.get(pk=commandeid)
except Commande.DoesNotExist:
messages.error(request, u"Credit inexistant" )
return redirect("/panier/")
if not request.user.has_perms(('bureau',)) and commande.user != request.user:
messages.error(request, "Vous ne pouvez pas commander pour quelqu'un d'autre !")
return redirect("/users/profil/" + str(request.user.id))
if request.method == "POST":
with transaction.atomic(), reversion.create_revision():
commande.delete()
reversion.set_user(request.user)
messages.success(request, "La commande a été détruite")
return redirect("/panier/")
return form({'objet': commande, 'objet_name': 'commande'}, 'panier/delete.html', request)
@login_required @login_required
@permission_required('bureau') @permission_required('bureau')
def add_livraison(request): def add_livraison(request):
...@@ -58,7 +129,7 @@ def edit_livraison(request, livraisonid): ...@@ -58,7 +129,7 @@ def edit_livraison(request, livraisonid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in livraison.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in livraison.changed_data))
messages.success(request, "Date modifiee") messages.success(request, "Date modifiee")
return redirect("/penier/index_livraison/") return redirect("/panier/index_livraison/")
return form({'panierform': livraison}, 'panier/panier.html', request) return form({'panierform': livraison}, 'panier/panier.html', request)
@login_required @login_required
...@@ -239,6 +310,15 @@ def history(request, object, id): ...@@ -239,6 +310,15 @@ def history(request, object, id):
if not request.user.has_perms(('bureau',)) and object_instance.user != request.user: if not request.user.has_perms(('bureau',)) and object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit ") messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit ")
return redirect("/panier/") return redirect("/panier/")
elif object == 'commande':
try:
object_instance = Commande.objects.get(pk=id)
except Commande.DoesNotExist:
messages.error(request, "Commande inexistante")
return redirect("/panier/")
if not request.user.has_perms(('bureau',)) and object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une commande d'un autre user que vous sans droit ")
return redirect("/panier/")
elif object == 'paiement' and request.user.has_perms(('bureau',)): elif object == 'paiement' and request.user.has_perms(('bureau',)):
try: try:
object_instance = Paiement.objects.get(pk=id) object_instance = Paiement.objects.get(pk=id)
...@@ -276,7 +356,7 @@ def history(request, object, id): ...@@ -276,7 +356,7 @@ def history(request, object, id):
@login_required @login_required
def index(request): def index(request):
paniers_list = Panier.objects.order_by('pk') paniers_list = Commande.objects.order_by('pk')
credit_list = Credit.objects.order_by('pk') credit_list = Credit.objects.order_by('pk')
if not request.user.has_perms(('bureau',)): if not request.user.has_perms(('bureau',)):
paniers_list = paniers_list.filter(user=request.user) paniers_list = paniers_list.filter(user=request.user)
...@@ -304,7 +384,6 @@ def index(request): ...@@ -304,7 +384,6 @@ def index(request):
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list}) return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list})
@login_required @login_required
@permission_required('bureau')
def index_article(request): def index_article(request):
article_list = Panier.objects.order_by('nom') article_list = Panier.objects.order_by('nom')
return render(request, 'panier/index_article.html', {'article_list':article_list}) return render(request, 'panier/index_article.html', {'article_list':article_list})
...@@ -316,7 +395,6 @@ def index_paiement(request): ...@@ -316,7 +395,6 @@ def index_paiement(request):
return render(request, 'panier/index_paiement.html', {'paiement_list':paiement_list}) return render(request, 'panier/index_paiement.html', {'paiement_list':paiement_list})
@login_required @login_required
@permission_required('bureau')
def index_livraison(request): def index_livraison(request):
livraison_list = Livraison.objects.order_by('date') livraison_list = Livraison.objects.order_by('date')
return render(request, 'panier/index_livraison.html', {'livraison_list':livraison_list}) return render(request, 'panier/index_livraison.html', {'livraison_list':livraison_list})
...@@ -13,6 +13,8 @@ import datetime ...@@ -13,6 +13,8 @@ import datetime
from django.utils import timezone from django.utils import timezone
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from panier.models import Credit, Commande
def get_admin_right(): def get_admin_right():
try: try:
admin_right = ListRight.objects.get(listright="admin") admin_right = ListRight.objects.get(listright="admin")
...@@ -132,10 +134,6 @@ class User(AbstractBaseUser): ...@@ -132,10 +134,6 @@ class User(AbstractBaseUser):
def has_perm(self, perm, obj=None): def has_perm(self, perm, obj=None):
return True return True
def has_access(self):
""" Renvoie si un utilisateur a accès à internet """
return self.state == User.STATE_ACTIVE
def has_module_perms(self, app_label): def has_module_perms(self, app_label):
# Simplest version again # Simplest version again
return True return True
...@@ -152,6 +150,12 @@ class User(AbstractBaseUser): ...@@ -152,6 +150,12 @@ class User(AbstractBaseUser):
return return
user_right.delete() user_right.delete()
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))
return credit-debit
def __str__(self): def __str__(self):
return self.pseudo return self.pseudo
......
...@@ -30,12 +30,13 @@ ...@@ -30,12 +30,13 @@
<td>{{ user.name }}</td> <td>{{ user.name }}</td>
<td>{{ user.surname }}</td> <td>{{ user.surname }}</td>
<td>{{ user.pseudo }}</td> <td>{{ user.pseudo }}</td>
<td>{% if user.has_access == True %} {% if user.state == 0 %}
<font color="green">Active</font> <td><font color="green">Actif</font></td>
{% elif user.state == 1 %}
<td><font color="red">Désactivé</font></td>
{% else %} {% else %}
<font color="red">Désactivée</font> <td><font color="orange">Archivé</font></td>
{% endif %} {% endif %}
</td>
<td>{{ user.telephone }}</td> <td>{{ user.telephone }}</td>
<td>{{ user.email }}</td> <td>{{ user.email }}</td>
<td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a> <td><a href="{% url "users:profil" user.id%}" class="btn btn-primary btn-sm" role="button"><i class="glyphicon glyphicon-user"></i></a>
......
...@@ -29,23 +29,17 @@ ...@@ -29,23 +29,17 @@
<th>Telephone</th> <th>Telephone</th>
<td>{{ user.telephone }}</td> <td>{{ user.telephone }}</td>
<th>Solde</th> <th>Solde</th>
<td></td> <td>{{ user.solde }} €</td>
</tr> </tr>
<tr> <tr>
<th>Commentaire</th>
<td>{{ user.comment }}</td>
<th>Date d'inscription</th> <th>Date d'inscription</th>
<td>{{ user.registered }}</td> <td>{{ user.registered }}</td>
</tr>
<tr>
<th>ENS</th> <th>ENS</th>
{% if user.is_ens %} {% if user.is_ens %}
<td><font color="green">Oui</font></td> <td><font color="green">Oui</font></td>
{% else %} {% else %}
<td><font color="red">Non</font></td> <td><font color="red">Non</font></td>
{% endif %} {% endif %}
<th>Solde</th>
<td></td>