Commit 3e8a7355 authored by Gabriel Detraz's avatar Gabriel Detraz

Empeche les commandes et modifications tardives

parent 16f92d3a
......@@ -25,7 +25,7 @@
<th>Prix</th>
<th>Livré</th>
<th>Date de livraison</th>
<th></th>
<th>Pas de modification après</th>
<th></th>
</tr>
</thead>
......@@ -41,17 +41,18 @@
{% else %}
<td><font color="red">Non</font></td>
{% endif %}
<td>{{ panier.date }}</td>
<td>{{ panier.date.date }}</td>
<td>{{ panier.date.date_modif }}</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
Editer
<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:edit-commande' panier.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Modifier</a></li>
<li><a href="{% url 'panier:history' 'commande' panier.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</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>
{% endfor %}
</table>
......
......@@ -18,6 +18,7 @@ from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, Li
from .forms import PanierForm, DelPanierForm, SelectArticleForm, BaseEditCommandeForm, NewCommandeForm
from users.views import User
from django.utils import timezone
from amap.settings import MINIMUM_LEVEL, PAGINATION_NUMBER
......@@ -47,6 +48,9 @@ def new_commande(request, userid):
commande = commande_form.save(commit=False)
prix_unitaire = article_form.cleaned_data['article'].prix
quantite = commande.quantite
if timezone.now() > commande.date.date_modif and not request.user.has_perms(('bureau',)):
messages.error(request, "Vous ne pouvez plus passer commande, livraison proche")
return redirect("/users/profil/" + str(request.user.id))
if user.solde() - prix_unitaire*quantite < MINIMUM_LEVEL:
messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/users/profil/" + userid)
......@@ -73,6 +77,9 @@ def edit_commande(request, commandeid):
if request.user.has_perms(('bureau',)):
commande = BaseEditCommandeForm(request.POST or None, instance=commande_instance)
else:
if timezone.now() > commande_instance.date.date_modif:
messages.error(request, "Vous ne pouvez plus modifier la commande, livraison proche")
return redirect("/users/profil/" + str(request.user.id))
commande = FullEditCommandeForm(request.POST or None, instance=commande_instance)
if commande.is_valid():
with transaction.atomic(), reversion.create_revision():
......@@ -93,6 +100,9 @@ def del_commande(request, commandeid):
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 timezone.now() > commande.date.date_modif and not request.user.has_perms(('bureau',)):
messages.error(request, "Vous ne pouvez plus supprimer la commande, livraison proche")
return redirect("/users/profil/" + str(request.user.id))
if request.method == "POST":
with transaction.atomic(), reversion.create_revision():
commande.delete()
......
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