mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 11:23:11 +00:00
Annulation des consommations
This commit is contained in:
parent
6aad16445e
commit
c506dde5c2
9 changed files with 274 additions and 11 deletions
21
gestion/migrations/0008_auto_20181130_1904.py
Normal file
21
gestion/migrations/0008_auto_20181130_1904.py
Normal 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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -180,7 +180,6 @@ class ConsumptionHistory(models.Model):
|
||||||
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
|
paymentMethod = models.ForeignKey(PaymentMethod, on_delete=models.PROTECT)
|
||||||
date = models.DateTimeField(auto_now_add=True)
|
date = models.DateTimeField(auto_now_add=True)
|
||||||
product = models.ForeignKey(Product, on_delete=models.PROTECT)
|
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)
|
amount = models.DecimalField(max_digits=7, decimal_places=2, default=0)
|
||||||
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled")
|
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="consumption_selled")
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
|
@ -31,6 +31,8 @@ urlpatterns = [
|
||||||
path('ranking', views.ranking, name="ranking"),
|
path('ranking', views.ranking, name="ranking"),
|
||||||
path('annualRanking', views.annualRanking, name="annualRanking"),
|
path('annualRanking', views.annualRanking, name="annualRanking"),
|
||||||
path('searchProduct', views.searchProduct, name="searchProduct"),
|
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('productProfile/<int:pk>', views.productProfile, name="productProfile"),
|
||||||
path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"),
|
path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"),
|
||||||
path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"),
|
path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"),
|
||||||
|
|
|
@ -115,8 +115,9 @@ def order(request):
|
||||||
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
||||||
consumption.quantity += quantity
|
consumption.quantity += quantity
|
||||||
consumption.save()
|
consumption.save()
|
||||||
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=article, amount=int(quantity*article.amount), coopeman=request.user, menu=mh)
|
if(article.stockHold > 0):
|
||||||
ch.save()
|
article.stockHold -= 1
|
||||||
|
article.save()
|
||||||
return HttpResponse("La commande a bien été effectuée")
|
return HttpResponse("La commande a bien été effectuée")
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -156,6 +157,28 @@ def refund(request):
|
||||||
messages.error(request, "Le remboursement a échoué")
|
messages.error(request, "Le remboursement a échoué")
|
||||||
return redirect(reverse('gestion:manage'))
|
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 ##########
|
########## Products ##########
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -452,4 +475,4 @@ def ranking(request):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def annualRanking(request):
|
def annualRanking(request):
|
||||||
return render(request, "gestion/annual_ranking.html")
|
return render(request, "gestion/annual_ranking.html")
|
||||||
|
|
61
users/templates/users/all_consumptions.html
Normal file
61
users/templates/users/all_consumptions.html
Normal 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 %}">« 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 »</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
{%endblock%}
|
61
users/templates/users/all_menus.html
Normal file
61
users/templates/users/all_menus.html
Normal 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 %}">« 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 »</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
{%endblock%}
|
|
@ -127,7 +127,7 @@
|
||||||
<section id="second" class="main">
|
<section id="second" class="main">
|
||||||
<header class="major">
|
<header class="major">
|
||||||
<h2>{{self | yesno:"Mes dernières,Dernières"}} consommations</h2>
|
<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>
|
</header>
|
||||||
<section id="transactions">
|
<section id="transactions">
|
||||||
<div class="table-wrapper">
|
<div class="table-wrapper">
|
||||||
|
@ -139,7 +139,7 @@
|
||||||
<th>Montant</th>
|
<th>Montant</th>
|
||||||
<th>Type de Paiement</th>
|
<th>Type de Paiement</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th></th>
|
<th>Annuler</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="bodyTransaction">
|
<tbody id="bodyTransaction">
|
||||||
|
@ -150,7 +150,41 @@
|
||||||
<td>{{c.amount}}</td>
|
<td>{{c.amount}}</td>
|
||||||
<td>{{c.paymentMethod}}</td>
|
<td>{{c.paymentMethod}}</td>
|
||||||
<td>{{c.date}}</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>
|
</tr>
|
||||||
{%endfor%}
|
{%endfor%}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -161,7 +195,7 @@
|
||||||
<section id="third" class="main">
|
<section id="third" class="main">
|
||||||
<header class="major">
|
<header class="major">
|
||||||
<h2>{{self | yesno:"Mes derniers,Derniers"}} rechargements</h2>
|
<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>
|
</header>
|
||||||
<section>
|
<section>
|
||||||
<div class="table-wrapper">
|
<div class="table-wrapper">
|
||||||
|
|
|
@ -41,4 +41,6 @@ urlpatterns = [
|
||||||
path('editSchool/<int:pk>', views.editSchool, name="editSchool"),
|
path('editSchool/<int:pk>', views.editSchool, name="editSchool"),
|
||||||
path('deleteSchool/<int:pk>', views.deleteSchool, name="deleteSchool"),
|
path('deleteSchool/<int:pk>', views.deleteSchool, name="deleteSchool"),
|
||||||
path('allReloads/<int:pk>/<int:page>', views.allReloads, name="allReloads"),
|
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"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -15,7 +15,7 @@ from dal import autocomplete
|
||||||
from coopeV3.acl import admin_required, superuser_required, self_or_has_perm, active_required
|
from coopeV3.acl import admin_required, superuser_required, self_or_has_perm, active_required
|
||||||
from .models import CotisationHistory, WhiteListHistory, School
|
from .models import CotisationHistory, WhiteListHistory, School
|
||||||
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm
|
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
|
@active_required
|
||||||
def loginView(request):
|
def loginView(request):
|
||||||
|
@ -123,6 +123,7 @@ def profile(request, pk):
|
||||||
products.append(ch.product)
|
products.append(ch.product)
|
||||||
quantities.append(ch.quantity)
|
quantities.append(ch.quantity)
|
||||||
lastConsumptions = ConsumptionHistory.objects.filter(customer=user).order_by('-date')[:10]
|
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",
|
return render(request, "users/profile.html",
|
||||||
{
|
{
|
||||||
"user":user,
|
"user":user,
|
||||||
|
@ -132,7 +133,8 @@ def profile(request, pk):
|
||||||
"reloads": reloads,
|
"reloads": reloads,
|
||||||
"products": products,
|
"products": products,
|
||||||
"quantities": quantities,
|
"quantities": quantities,
|
||||||
"lastConsumptions": lastConsumptions
|
"lastConsumptions": lastConsumptions,
|
||||||
|
"lastMenus": lastMenus,
|
||||||
})
|
})
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
@ -380,10 +382,68 @@ def allReloads(request, pk, page):
|
||||||
"""
|
"""
|
||||||
user = get_object_or_404(User, pk=pk)
|
user = get_object_or_404(User, pk=pk)
|
||||||
allReloads = Reload.objects.filter(customer=user).order_by('-date')
|
allReloads = Reload.objects.filter(customer=user).order_by('-date')
|
||||||
paginator = Paginator(allReloads, 2)
|
paginator = Paginator(allReloads, 10)
|
||||||
reloads = paginator.get_page(page)
|
reloads = paginator.get_page(page)
|
||||||
return render(request, "users/allReloads.html", {"reloads": reloads, "user":user})
|
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 ##########
|
########## Groups ##########
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
|
Loading…
Reference in a new issue