From b0d3084d4b73765dab9a84e6ffff7ebbd39e95b6 Mon Sep 17 00:00:00 2001 From: nanoy Date: Mon, 24 Dec 2018 01:30:00 +0100 Subject: [PATCH] Annulation de rechargement --- gestion/urls.py | 1 + gestion/views.py | 21 ++++++++++++++++++++- users/templates/users/allReloads.html | 12 +++++++++--- users/templates/users/profile.html | 6 ++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/gestion/urls.py b/gestion/urls.py index 2fa4368..dd18cbc 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -43,4 +43,5 @@ urlpatterns = [ path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"), path('kegs-active-autocomplete', views.KegActiveAutocomplete.as_view(), name="kegs-active-autocomplete"), path('menus-autcomplete', views.MenusAutocomplete.as_view(), name="menus-autocomplete"), + path('cancelReload/', views.cancel_reload, name="cancelReload"), ] \ No newline at end of file diff --git a/gestion/views.py b/gestion/views.py index 727be04..48a0e67 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -6,6 +6,7 @@ from django.contrib.auth.models import User from django.views.decorators.csrf import csrf_exempt from django.contrib.auth.decorators import login_required, permission_required from django.utils import timezone +from django.http import HttpResponseRedirect from coopeV3.acl import active_required, acl_or @@ -14,7 +15,7 @@ from dal import autocomplete from decimal import * from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm -from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte +from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload from preferences.models import PaymentMethod, GeneralPreferences @active_required @@ -205,6 +206,24 @@ def reload(request): messages.error(request, "Le rechargement a échoué") return redirect(reverse('gestion:manage')) +@active_required +@login_required +@permission_required('gestion.delete_reload') +def cancel_reload(request, pk): + """ + Cancel a reload + """ + reload_entry = get_object_or_404(Reload, pk=pk) + if reload_entry.customer.profile.balance >= reload_entry.amount: + reload_entry.customer.profile.credit -= reload_entry.amount + reload_entry.customer.save() + reload_entry.delete() + messages.success(request, "Le rechargement a bien été annulé.") + else: + messages.error(request, "Impossible d'annuler le rechargement. Le solde deviendrait négatif.") + return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + + @active_required @login_required @permission_required('gestion.add_refund') diff --git a/users/templates/users/allReloads.html b/users/templates/users/allReloads.html index 5b4f4de..e06fe90 100644 --- a/users/templates/users/allReloads.html +++ b/users/templates/users/allReloads.html @@ -20,14 +20,20 @@ Montant Type de Rechargement Date + {% if perms.gestion.delete_reload %} + Annuler + {% endif %} {% for reload in reloads %} - {{reload.amount}}€ - {{reload.PaymentMethod}} - {{reload.date}} + {{reload.amount}}€ + {{reload.PaymentMethod}} + {{reload.date}} + {% if perms.gestion.delete_reload %} + Annuler + {% endif %} {% endfor %} diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index e4ceb35..03b52d3 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -209,6 +209,9 @@ Montant Type de Rechargement Date + {% if perms.gestion.delete_reload %} + Annuler + {% endif %} @@ -217,6 +220,9 @@ {{reload.amount}} € {{reload.PaymentMethod}} {{reload.date}} + {% if perms.gestion.delete_reload %} + Annuler + {% endif %} {% endfor %}