3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-12-23 23:43:47 +00:00

Annulation des consommations

This commit is contained in:
Yoann Pétri 2018-11-30 19:54:12 +01:00
parent 6aad16445e
commit c506dde5c2
9 changed files with 274 additions and 11 deletions

View file

@ -0,0 +1,21 @@
# Generated by Django 2.1 on 2018-11-30 18:04
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('gestion', '0007_auto_20181127_0902'),
]
operations = [
migrations.RemoveField(
model_name='consumptionhistory',
name='menu',
),
migrations.RemoveField(
model_name='historicalconsumptionhistory',
name='menu',
),
]

View file

@ -180,7 +180,6 @@ class ConsumptionHistory(models.Model):
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
date = models.DateTimeField(auto_now_add=True)
product = models.ForeignKey(Product, on_delete=models.PROTECT)
menu = models.ForeignKey(MenuHistory, on_delete=models.CASCADE, null=True, blank=True)
amount = models.DecimalField(max_digits=7, decimal_places=2, default=0)
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled")
history = HistoricalRecords()

View file

@ -31,6 +31,8 @@ urlpatterns = [
path('ranking', views.ranking, name="ranking"),
path('annualRanking', views.annualRanking, name="annualRanking"),
path('searchProduct', views.searchProduct, name="searchProduct"),
path('cancelConsumption/<int:pk>', views.cancel_consumption, name="cancelConsumption"),
path('cancelMenu/<int:pk>', views.cancel_menu, name="cancelMenu"),
path('productProfile/<int:pk>', views.productProfile, name="productProfile"),
path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"),
path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"),

View file

@ -115,8 +115,9 @@ def order(request):
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
consumption.quantity += quantity
consumption.save()
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=article, amount=int(quantity*article.amount), coopeman=request.user, menu=mh)
ch.save()
if(article.stockHold > 0):
article.stockHold -= 1
article.save()
return HttpResponse("La commande a bien été effectuée")
@login_required
@ -156,6 +157,28 @@ def refund(request):
messages.error(request, "Le remboursement a échoué")
return redirect(reverse('gestion:manage'))
@login_required
@permission_required('gestion.delete_consumptionhistory')
def cancel_consumption(request, pk):
consumption = get_object_or_404(ConsumptionHistory, pk=pk)
user = consumption.customer
user.profile.debit -= consumption.amount
user.save()
consumption.delete()
messages.success(request, "La consommation a bien été annulée")
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
@login_required
@permission_required('gestion.delete_menuhistory')
def cancel_menu(request, pk):
menu_history = get_object_or_404(MenuHistory, pk=pk)
user = menu_history.customer
user.profile.debit -= menu_history.amount
user.save()
menu_history.delete()
messages.success(request, "La consommation du menu a bien été annulée")
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
########## Products ##########
@login_required
@ -452,4 +475,4 @@ def ranking(request):
@login_required
def annualRanking(request):
return render(request, "gestion/annual_ranking.html")
return render(request, "gestion/annual_ranking.html")

View file

@ -0,0 +1,61 @@
{% extends "base.html" %}
{% load static %}
{% block entete %}<h1>Consommations</h1>{%endblock%}
{% block navbar %}
<ul>
<li><a href="#first">Consommations ({{user}})</a></li>
</ul>
{% endblock %}
{% block content %}
<section id="first" class="main special">
<header class="major">
<h2>Consommations ({{user}})</h2>
</header>
<section id="rechargements">
<div class="table-wrapper">
<table>
<thead id="headTransaction">
<tr>
<th>Produit</th>
<th>Quantité</th>
<th>Montant</th>
<th>Type de Paiement</th>
<th>Date</th>
<th>Annuler</th>
</tr>
</thead>
<tbody id="bodyTransaction">
{% for c in consumptions %}
<tr>
<td>{{c.product}}</td>
<td>{{c.quantity}}</td>
<td>{{c.amount}}</td>
<td>{{c.paymentMethod}}</td>
<td>{{c.date}}</td>
<td><a href="{% url 'gestion:cancelConsumption' c.pk %}" class="button small">Annuler</a></td>
</tr>
{%endfor%}
</tbody>
</table>
</div>
<div class="pagination special">
<span class="step-links">
{% if consumptions.has_previous %}
<a href="{% url 'users:allConsumptions' user.pk 1 %}">&laquo; Première </a>
<a href="{% url 'users:allConsumptions' user.pk consumptions.previous_page_number %}"> Précédente </a>
{% endif %}
<span class="current">
Page {{ consumptions.number }} sur {{ consumptions.paginator.num_pages }}.
</span>
{% if consumptions.has_next %}
<a href="{% url 'users:allConsumptions' user.pk consumptions.next_page_number %}"> Suivante </a>
<a href="{% url 'users:allConsumptions' user.pk consumptions.paginator.num_pages %}"> Dernière &raquo;</a>
{% endif %}
</span>
</div>
</section>
</section>
{%endblock%}

View file

@ -0,0 +1,61 @@
{% extends "base.html" %}
{% load static %}
{% block entete %}<h1>Menus</h1>{%endblock%}
{% block navbar %}
<ul>
<li><a href="#first">Consommations de menus ({{user}})</a></li>
</ul>
{% endblock %}
{% block content %}
<section id="first" class="main special">
<header class="major">
<h2>Consommations de menus ({{user}})</h2>
</header>
<section id="rechargements">
<div class="table-wrapper">
<table>
<thead id="headTransaction">
<tr>
<th>Menu</th>
<th>Quantité</th>
<th>Montant</th>
<th>Type de Paiement</th>
<th>Date</th>
<th>Annuler</th>
</tr>
</thead>
<tbody id="bodyTransaction">
{% for m in menus %}
<tr>
<td>{{m.menu}}</td>
<td>{{m.quantity}}</td>
<td>{{m.amount}}</td>
<td>{{m.paymentMethod}}</td>
<td>{{m.date}}</td>
<td><a href="{% url 'gestion:cancelMenu' m.pk %}" class="button small">Annuler</a></td>
</tr>
{%endfor%}
</tbody>
</table>
</div>
<div class="pagination special">
<span class="step-links">
{% if menus.has_previous %}
<a href="{% url 'users:allMenus' user.pk 1 %}">&laquo; Première </a>
<a href="{% url 'users:allMenus' user.pk menus.previous_page_number %}"> Précédente </a>
{% endif %}
<span class="current">
Page {{ menus.number }} sur {{ menus.paginator.num_pages }}.
</span>
{% if menus.has_next %}
<a href="{% url 'users:allMenus' user.pk menus.next_page_number %}"> Suivante </a>
<a href="{% url 'users:allMenus' user.pk menus.paginator.num_pages %}"> Dernière &raquo;</a>
{% endif %}
</span>
</div>
</section>
</section>
{%endblock%}

View file

@ -127,7 +127,7 @@
<section id="second" class="main">
<header class="major">
<h2>{{self | yesno:"Mes dernières,Dernières"}} consommations</h2>
<p>(Affichage des 10 dernières entrées)</p>
<p>(Affichage des 10 dernières entrées : <a href="{% url 'users:allConsumptions' user.pk 1 %}">Voir toutes les entrées</a>)</p>
</header>
<section id="transactions">
<div class="table-wrapper">
@ -139,7 +139,7 @@
<th>Montant</th>
<th>Type de Paiement</th>
<th>Date</th>
<th></th>
<th>Annuler</th>
</tr>
</thead>
<tbody id="bodyTransaction">
@ -150,7 +150,41 @@
<td>{{c.amount}}</td>
<td>{{c.paymentMethod}}</td>
<td>{{c.date}}</td>
<td></td>
<td><a href="{% url 'gestion:cancelConsumption' c.pk %}" class="button small">Annuler</a></td>
</tr>
{%endfor%}
</tbody>
</table>
</div>
</section>
</section>
<section id="secondbis" class="main">
<header class="major">
<h2>{{self | yesno:"Mes derniers,Derniers"}} menus</h2>
<p>(Affichage des 5 dernières entrées : <a href="{% url 'users:allMenus' user.pk 1 %}">Voir toutes les entrées</a>)</p>
</header>
<section id="transactions">
<div class="table-wrapper">
<table>
<thead id="headTransaction">
<tr>
<th>Menu</th>
<th>Quantité</th>
<th>Montant</th>
<th>Type de Paiement</th>
<th>Date</th>
<th>Annuler</th>
</tr>
</thead>
<tbody id="bodyTransaction">
{% for m in lastMenus %}
<tr>
<td>{{m.menu}}</td>
<td>{{m.quantity}}</td>
<td>{{m.amount}}</td>
<td>{{m.paymentMethod}}</td>
<td>{{m.date}}</td>
<td><a href="{% url 'gestion:cancelMenu' m.pk %}" class="button small">Annuler</a></td>
</tr>
{%endfor%}
</tbody>
@ -161,7 +195,7 @@
<section id="third" class="main">
<header class="major">
<h2>{{self | yesno:"Mes derniers,Derniers"}} rechargements</h2>
<p>(Affichage des 5 dernières entrées)</p>
<p>(Affichage des 5 dernières entrées : <a href="{% url 'users:allReloads' user.pk 1 %}">Voir toutes les entrées</a>)</p>
</header>
<section>
<div class="table-wrapper">

View file

@ -41,4 +41,6 @@ urlpatterns = [
path('editSchool/<int:pk>', views.editSchool, name="editSchool"),
path('deleteSchool/<int:pk>', views.deleteSchool, name="deleteSchool"),
path('allReloads/<int:pk>/<int:page>', views.allReloads, name="allReloads"),
path('allConsumptions/<int:pk>/<int:page>', views.all_consumptions, name="allConsumptions"),
path('allMenus/<int:pk>/<int:page>', views.all_menus, name="allMenus"),
]

View file

@ -15,7 +15,7 @@ from dal import autocomplete
from coopeV3.acl import admin_required, superuser_required, self_or_has_perm, active_required
from .models import CotisationHistory, WhiteListHistory, School
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm
from gestion.models import Reload, Consumption, ConsumptionHistory
from gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
@active_required
def loginView(request):
@ -123,6 +123,7 @@ def profile(request, pk):
products.append(ch.product)
quantities.append(ch.quantity)
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
lastMenus = MenuHistory.objects.filter(customer=user).order_by('-date')[:10]
return render(request, "users/profile.html",
{
"user":user,
@ -132,7 +133,8 @@ def profile(request, pk):
"reloads": reloads,
"products": products,
"quantities": quantities,
"lastConsumptions": lastConsumptions
"lastConsumptions": lastConsumptions,
"lastMenus": lastMenus,
})
@active_required
@ -380,10 +382,68 @@ def allReloads(request, pk, page):
"""
user = get_object_or_404(User, pk=pk)
allReloads = Reload.objects.filter(customer=user).order_by('-date')
paginator = Paginator(allReloads, 2)
paginator = Paginator(allReloads, 10)
reloads = paginator.get_page(page)
return render(request, "users/allReloads.html", {"reloads": reloads, "user":user})
@active_required
@login_required
@self_or_has_perm('pk', 'auth.view_user')
def all_consumptions(request, pk, page):
"""
Display all the consumptions of the requested user.
``pk``
The pk of the user.
``page``
The page number.
**Context**
``reloads``
The reloads of the page.
``user``
The requested user
**Template**
:template:`users/all_consumptions.html`
"""
user = get_object_or_404(User, pk=pk)
all_consumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')
paginator = Paginator(all_consumptions, 10)
consumptions = paginator.get_page(page)
return render(request, "users/all_consumptions.html", {"consumptions": consumptions, "user":user})
@active_required
@login_required
@self_or_has_perm('pk', 'auth.view_user')
def all_menus(request, pk, page):
"""
Display all the menus of the requested user.
``pk``
The pk of the user.
``page``
The page number.
**Context**
``reloads``
The reloads of the page.
``user``
The requested user
**Template**
:template:`users/all_menus.html`
"""
user = get_object_or_404(User, pk=pk)
all_menus = MenuHistory.objects.filter(customer=user).order_by('-date')
paginator = Paginator(all_menus, 10)
menus = paginator.get_page(page)
return render(request, "users/all_menus.html", {"menus": menus, "user":user})
########## Groups ##########
@active_required