mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 11:23:11 +00:00
Annulation de rechargement
This commit is contained in:
parent
db2c82cfe7
commit
b0d3084d4b
4 changed files with 36 additions and 4 deletions
|
@ -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/<int:pk>', views.cancel_reload, name="cancelReload"),
|
||||
]
|
|
@ -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')
|
||||
|
|
|
@ -20,14 +20,20 @@
|
|||
<th>Montant</th>
|
||||
<th>Type de Rechargement</th>
|
||||
<th>Date</th>
|
||||
{% if perms.gestion.delete_reload %}
|
||||
<th>Annuler</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="bodyRechargement">
|
||||
{% for reload in reloads %}
|
||||
<tr>
|
||||
<th>{{reload.amount}}€</th>
|
||||
<th>{{reload.PaymentMethod}}</th>
|
||||
<th>{{reload.date}}</th>
|
||||
<td>{{reload.amount}}€</td>
|
||||
<td>{{reload.PaymentMethod}}</td>
|
||||
<td>{{reload.date}}</td>
|
||||
{% if perms.gestion.delete_reload %}
|
||||
<td><a href="{% url 'gestion:cancelReload' reload.pk %}" class="button small">Annuler</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -209,6 +209,9 @@
|
|||
<th>Montant</th>
|
||||
<th>Type de Rechargement</th>
|
||||
<th>Date</th>
|
||||
{% if perms.gestion.delete_reload %}
|
||||
<th>Annuler</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -217,6 +220,9 @@
|
|||
<td>{{reload.amount}} €</td>
|
||||
<td>{{reload.PaymentMethod}}</td>
|
||||
<td>{{reload.date}}</td>
|
||||
{% if perms.gestion.delete_reload %}
|
||||
<th><a href="{% url 'gestion:cancelReload' reload.pk %}" class="button small">Annuler</a></th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue