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

Empeche les commandes et modifications tardives

parent 16f92d3a
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<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>Pas de modification après</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
...@@ -41,17 +41,18 @@ ...@@ -41,17 +41,18 @@
{% else %} {% else %}
<td><font color="red">Non</font></td> <td><font color="red">Non</font></td>
{% endif %} {% endif %}
<td>{{ panier.date }}</td> <td>{{ panier.date.date }}</td>
<td>{{ panier.date.date_modif }}</td>
<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">
Modifier Editer
<span class="caret"></span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" aria-labelledby="editionfacture"> <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> <li><a href="{% url 'panier:del-commande' panier.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
</ul></div></td> </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>
......
...@@ -18,6 +18,7 @@ from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, Li ...@@ -18,6 +18,7 @@ from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, Li
from .forms import PanierForm, DelPanierForm, SelectArticleForm, BaseEditCommandeForm, NewCommandeForm from .forms import PanierForm, DelPanierForm, SelectArticleForm, BaseEditCommandeForm, NewCommandeForm
from users.views import User from users.views import User
from django.utils import timezone
from amap.settings import MINIMUM_LEVEL, PAGINATION_NUMBER from amap.settings import MINIMUM_LEVEL, PAGINATION_NUMBER
...@@ -47,6 +48,9 @@ def new_commande(request, userid): ...@@ -47,6 +48,9 @@ def new_commande(request, userid):
commande = commande_form.save(commit=False) commande = commande_form.save(commit=False)
prix_unitaire = article_form.cleaned_data['article'].prix prix_unitaire = article_form.cleaned_data['article'].prix
quantite = commande.quantite 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: if user.solde() - prix_unitaire*quantite < MINIMUM_LEVEL:
messages.error(request, "Solde insuffisant pour effectuer l'operation") messages.error(request, "Solde insuffisant pour effectuer l'operation")
return redirect("/users/profil/" + userid) return redirect("/users/profil/" + userid)
...@@ -73,6 +77,9 @@ def edit_commande(request, commandeid): ...@@ -73,6 +77,9 @@ def edit_commande(request, commandeid):
if request.user.has_perms(('bureau',)): if request.user.has_perms(('bureau',)):
commande = BaseEditCommandeForm(request.POST or None, instance=commande_instance) commande = BaseEditCommandeForm(request.POST or None, instance=commande_instance)
else: 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) commande = FullEditCommandeForm(request.POST or None, instance=commande_instance)
if commande.is_valid(): if commande.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
...@@ -93,6 +100,9 @@ def del_commande(request, commandeid): ...@@ -93,6 +100,9 @@ def del_commande(request, commandeid):
if not request.user.has_perms(('bureau',)) and commande.user != request.user: 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 !") messages.error(request, "Vous ne pouvez pas commander pour quelqu'un d'autre !")
return redirect("/users/profil/" + str(request.user.id)) 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": if request.method == "POST":
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
commande.delete() 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