Commit 8e3a1d9e authored by Amap's avatar Amap

Modifie le menu du tableau de bord

parent 57728b6a
...@@ -6,10 +6,10 @@ from reversion.admin import VersionAdmin ...@@ -6,10 +6,10 @@ from reversion.admin import VersionAdmin
from .models import Panier, Commande, Credit, Paiement, Livraison from .models import Panier, Commande, Credit, Paiement, Livraison
class PanierAdmin(VersionAdmin): class PanierAdmin(VersionAdmin):
list_display = ('prix','nom') list_display = ('prix','coefficient_panier','nom')
class CommandeAdmin(VersionAdmin): class CommandeAdmin(VersionAdmin):
list_display = ('user', 'quantite', 'prix_unitaire', 'nom', 'livre', 'date') list_display = ('user', 'quantite', 'coefficient_panier', 'prix_unitaire', 'nom', 'livre', 'date')
class CreditAdmin(VersionAdmin): class CreditAdmin(VersionAdmin):
list_display = ('user','montant','moyen','validite') list_display = ('user','montant','moyen','validite')
......
...@@ -22,7 +22,7 @@ class SelectArticleForm(ModelForm): ...@@ -22,7 +22,7 @@ class SelectArticleForm(ModelForm):
article = forms.ModelChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement") article = forms.ModelChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement")
class Meta: class Meta:
exclude = ['nom','prix'] exclude = ['nom','prix','coefficient_panier']
model = Panier model = Panier
...@@ -62,7 +62,7 @@ class DelPaiementForm(ModelForm): ...@@ -62,7 +62,7 @@ class DelPaiementForm(ModelForm):
class PanierForm(ModelForm): class PanierForm(ModelForm):
class Meta: class Meta:
model = Panier model = Panier
fields = ['nom','prix'] fields = ['nom','prix','coefficient_panier']
class DelPanierForm(ModelForm): class DelPanierForm(ModelForm):
paniers = forms.ModelMultipleChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement", widget=forms.CheckboxSelectMultiple) paniers = forms.ModelMultipleChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement", widget=forms.CheckboxSelectMultiple)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0007_auto_20160930_2259'),
]
operations = [
migrations.AddField(
model_name='commande',
name='coef_panier',
field=models.DecimalField(null=True, decimal_places=1, max_digits=1, blank=True),
),
migrations.AddField(
model_name='panier',
name='coef_panier',
field=models.DecimalField(null=True, decimal_places=1, max_digits=1, blank=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0008_auto_20161005_0215'),
]
operations = [
migrations.RenameField(
model_name='commande',
old_name='coef_panier',
new_name='coefficient_panier',
),
migrations.RenameField(
model_name='panier',
old_name='coef_panier',
new_name='coefficient_panier',
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0009_auto_20161005_0219'),
]
operations = [
migrations.AlterField(
model_name='commande',
name='coefficient_panier',
field=models.DecimalField(decimal_places=1, null=True, blank=True, max_digits=2),
),
migrations.AlterField(
model_name='panier',
name='coefficient_panier',
field=models.DecimalField(decimal_places=1, null=True, blank=True, max_digits=2),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0010_auto_20161005_0223'),
]
operations = [
migrations.AlterField(
model_name='commande',
name='coefficient_panier',
field=models.DecimalField(blank=True, decimal_places=2, null=True, max_digits=3),
),
migrations.AlterField(
model_name='panier',
name='coefficient_panier',
field=models.DecimalField(blank=True, decimal_places=2, null=True, max_digits=3),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0011_auto_20161005_0224'),
]
operations = [
migrations.AlterField(
model_name='commande',
name='coefficient_panier',
field=models.DecimalField(null=True, max_digits=3, decimal_places=2),
),
migrations.AlterField(
model_name='panier',
name='coefficient_panier',
field=models.DecimalField(null=True, max_digits=3, decimal_places=2),
),
]
...@@ -10,6 +10,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator ...@@ -10,6 +10,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator
class Panier(models.Model): class Panier(models.Model):
prix = models.DecimalField(max_digits=5, decimal_places=2) prix = models.DecimalField(max_digits=5, decimal_places=2)
nom = models.CharField(max_length=255) nom = models.CharField(max_length=255)
coefficient_panier = models.DecimalField(max_digits=3, decimal_places=2, null=True)
def __str__(self): def __str__(self):
return self.nom return self.nom
...@@ -17,6 +18,7 @@ class Panier(models.Model): ...@@ -17,6 +18,7 @@ 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) nom = models.CharField(max_length=255)
coefficient_panier = models.DecimalField(max_digits=3, decimal_places=2, null=True)
quantite = models.PositiveIntegerField(validators=[MinValueValidator(1)]) quantite = models.PositiveIntegerField(validators=[MinValueValidator(1)])
prix_unitaire = 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)
......
...@@ -2,17 +2,20 @@ ...@@ -2,17 +2,20 @@
<thead> <thead>
<tr> <tr>
<th>Nom de l'article</th> <th>Nom de l'article</th>
<th>Coefficient panier</th>
<th>Prix unitaire</th> <th>Prix unitaire</th>
<th></th> <th></th>
<th></th>
</tr> </tr>
</thead> </thead>
{% for article in article_list %} {% for article in article_list %}
<tr> <tr>
<td>{{ article.nom }}</td> <td>{{ article.nom }}</td>
<td>{{ article.coefficient_panier }}</td>
<td>{{ article.prix }}</td> <td>{{ article.prix }}</td>
{% if is_bureau %} {% 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></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> <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 %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
......
...@@ -2,24 +2,30 @@ ...@@ -2,24 +2,30 @@
<h2>Tableau de bord</h2> <h2>Tableau de bord</h2>
<table class="table table-striped"> <table class="table table-striped">
<thead>
<tr> <tr>
<th>Solde total des comptes</th> <th>Solde total des comptes</th>
<td>{{ solde_total }}</td>
<th>Solde moyen</th>
<td>{{ solde_moyen }}</td>
</tr>
<tr>
<th>Nombres de comptes actifs</th> <th>Nombres de comptes actifs</th>
<td>{{ user_total }}</td>
<th>Dont ENS</th> <th>Dont ENS</th>
<th>Solde moyen</th> <td>{{ user_ens }}</td>
<th>Nombre de commandes</th> </tr>
<tr>
<th>Nombre total de commandes</th>
<td>{{ commandes_total }}</td>
<th>Prochaine livraison</th> <th>Prochaine livraison</th>
<td>{{ next_livraison.date }}</td>
</tr>
<tr>
<th>Commandes pour la prochaine livraison</th>
<td>{{ next_livraison_commandes }}</td>
<th>Paniers pour la prochaine livraison</th>
<td>{{ next_livraison_paniers }}</td>
</tr> </tr>
</thead>
<tr>
<td>{{ solde_total }}</td>
<td>{{ user_total }}</td>
<td>{{ user_ens }}</td>
<td>{{ solde_moyen }}</td>
<td>{{ commandes_total }}</td>
<td>{{ next_livraison.date }}</td>
</tr>
</table> </table>
{% endif %} {% endif %}
...@@ -57,8 +63,8 @@ ...@@ -57,8 +63,8 @@
</thead> </thead>
{% for panier in paniers_list %} {% for panier in paniers_list %}
<tr> <tr>
<td>{{ panier.user.name }}</td>
<td>{{ panier.user.surname }}</td> <td>{{ panier.user.surname }}</td>
<td>{{ panier.user.name }}</td>
<td>{{ panier.nom }}</td> <td>{{ panier.nom }}</td>
<td>{{ panier.quantite }}</td> <td>{{ panier.quantite }}</td>
<td>{{ panier.prix }}</td> <td>{{ panier.prix }}</td>
...@@ -114,8 +120,8 @@ ...@@ -114,8 +120,8 @@
</thead> </thead>
{% for credit in credit_list %} {% for credit in credit_list %}
<tr> <tr>
<td>{{ credit.user.name }}</td>
<td>{{ credit.user.surname }}</td> <td>{{ credit.user.surname }}</td>
<td>{{ credit.user.name }}</td>
<td>{{ credit.montant }}</td> <td>{{ credit.montant }}</td>
<td>{{ credit.moyen }}</td> <td>{{ credit.moyen }}</td>
{% if credit.validite %} {% if credit.validite %}
......
...@@ -51,6 +51,7 @@ def new_commande(request, userid): ...@@ -51,6 +51,7 @@ def new_commande(request, userid):
commande = commande_form.save(commit=False) commande = commande_form.save(commit=False)
commande.prix_unitaire = article_form.cleaned_data['article'].prix commande.prix_unitaire = article_form.cleaned_data['article'].prix
commande.nom = article_form.cleaned_data['article'].nom commande.nom = article_form.cleaned_data['article'].nom
commande.coefficient_panier = article_form.cleaned_data['article'].coefficient_panier
# Si non surdroits, check solde et date # Si non surdroits, check solde et date
if not request.user.has_perms(('bureau',)): if not request.user.has_perms(('bureau',)):
if timezone.now() > commande.date.date_modif: if timezone.now() > commande.date.date_modif:
...@@ -422,8 +423,8 @@ def history(request, object, id): ...@@ -422,8 +423,8 @@ def history(request, object, id):
@login_required @login_required
def index(request): def index(request):
paniers_list = Commande.objects.order_by('pk') paniers_list = Commande.objects.order_by('pk').reverse()
credit_list = Credit.objects.order_by('pk') credit_list = Credit.objects.order_by('pk').reverse()
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)
credit_list = credit_list.filter(user=request.user) credit_list = credit_list.filter(user=request.user)
...@@ -457,7 +458,9 @@ def index(request): ...@@ -457,7 +458,9 @@ def index(request):
next_livraison = Livraison.objects.order_by('date').filter(date__gt=timezone.now())[0] next_livraison = Livraison.objects.order_by('date').filter(date__gt=timezone.now())[0]
except IndexError: except IndexError:
next_livraison = None next_livraison = None
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}) next_livraison_commandes = len(Commande.objects.filter(date=Livraison.objects.filter(date=next_livraison.date)))
next_livraison_paniers = sum(pan.coefficient_panier*pan.quantite for pan in Commande.objects.filter(date=Livraison.objects.filter(date=next_livraison.date)))
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, 'next_livraison_commandes': next_livraison_commandes, 'next_livraison_paniers': next_livraison_paniers})
@login_required @login_required
def index_article(request): def index_article(request):
......
...@@ -229,7 +229,7 @@ def del_listright(request): ...@@ -229,7 +229,7 @@ def del_listright(request):
@login_required @login_required
@permission_required('bureau') @permission_required('bureau')
def index(request): def index(request):
users_list = User.objects.order_by('pk') users_list = User.objects.order_by('surname')
paginator = Paginator(users_list, PAGINATION_NUMBER) paginator = Paginator(users_list, PAGINATION_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
......
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