diff --git a/gestion/templates/gestion/products_index.html b/gestion/templates/gestion/products_index.html index 5b5543a..7df35e8 100644 --- a/gestion/templates/gestion/products_index.html +++ b/gestion/templates/gestion/products_index.html @@ -66,13 +66,13 @@ Actions possibles : diff --git a/gestion/urls.py b/gestion/urls.py index e2bc803..ffce4b8 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -33,8 +33,10 @@ urlpatterns = [ path('cancelConsumption/', views.cancel_consumption, name="cancelConsumption"), path('cancelMenu/', views.cancel_menu, name="cancelMenu"), path('productProfile/', views.productProfile, name="productProfile"), - path('createPintes', views.create_pintes, name="createPintes"), + path('addPintes', views.add_pintes, name="addPintes"), path('releasePintes', views.release_pintes, name="releasePintes"), + path('pintesList', views.pintes_list, name="pintesList"), + path('release/', views.release, name="release"), path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"), path('kegs-positive-autocomplete', views.KegPositiveAutocomplete.as_view(), name="kegs-positive-autocomplete"), path('kegs-active-autocomplete', views.KegActiveAutocomplete.as_view(), name="kegs-active-autocomplete"), diff --git a/gestion/views.py b/gestion/views.py index 0e70809..1767943 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -914,10 +914,23 @@ def allocate(pinte_pk, user): except Pinte.DoesNotExist: return False +@active_required +@login_required +@permission_required('gestion.change_pinte') +def release(request, pinte_pk): + """ + View to release a pinte + """ + if allocate(pinte_pk, None): + messages.success(request, "La pinte a bien été libérée") + else: + messages.error(request, "Impossible de libérer la pinte") + return redirect(reverse('gestion:pintesList')) + @active_required @login_required @permission_required('gestion.add_pinte') -def create_pintes(request): +def add_pintes(request): form = PinteForm(request.POST or None) if form.is_valid(): ids = form.cleaned_data['ids'] @@ -952,4 +965,12 @@ def release_pintes(request): i += 1 messages.success(request, str(i) + " pinte(s) a(ont) été libérée(s)") return redirect(reverse('gestion:productsIndex')) - return render(request, "form.html", {"form": form, "form_title": "Libérer des pintes", "form_button": "Libérer"}) \ No newline at end of file + return render(request, "form.html", {"form": form, "form_title": "Libérer des pintes", "form_button": "Libérer"}) + +@active_required +@login_required +@permission_required('gestion.view_pinte') +def pintes_list(request): + free_pintes = Pinte.objects.filter(current_owner=None) + taken_pintes = Pinte.objects.exclude(current_owner=None) + return render(request, "gestion/pintes_list.html", {"free_pintes": free_pintes, "taken_pintes": taken_pintes}) \ No newline at end of file