From 1a1b5cf60b4bc0aaaa231a41daf32bab2bd5c6c0 Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 23 Dec 2018 12:54:37 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20pintes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/forms.py | 7 +++++- gestion/templates/gestion/products_index.html | 18 +++++++++++++ gestion/urls.py | 1 + gestion/views.py | 25 +++++++++++++++++-- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/gestion/forms.py b/gestion/forms.py index 95894b7..0c560a8 100644 --- a/gestion/forms.py +++ b/gestion/forms.py @@ -60,4 +60,9 @@ class SelectPositiveKegForm(forms.Form): keg = forms.ModelChoiceField(queryset=Keg.objects.filter(stockHold__gt = 0), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-positive-autocomplete')) class SelectActiveKegForm(forms.Form): - keg = forms.ModelChoiceField(queryset=Keg.objects.filter(is_active = True), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-active-autocomplete')) \ No newline at end of file + keg = forms.ModelChoiceField(queryset=Keg.objects.filter(is_active = True), required=True, label="Fût", widget=autocomplete.ModelSelect2(url='gestion:kegs-active-autocomplete')) + +class CreatePinteForm(forms.Form): + ids = forms.CharField(widget=forms.Textarea, label="Numéros", help_text="Numéros séparés par un espace. Laissez vide pour utiliser le range.", required=False) + begin = forms.IntegerField(label="Début", help_text="Début du range", required=False) + end = forms.IntegerField(label="Fin", help_text="Fin du range", required=False) \ No newline at end of file diff --git a/gestion/templates/gestion/products_index.html b/gestion/templates/gestion/products_index.html index 2a3ade6..21b8393 100644 --- a/gestion/templates/gestion/products_index.html +++ b/gestion/templates/gestion/products_index.html @@ -5,6 +5,7 @@
  • Produits
  • Futs
  • Menus
  • +
  • Pintes
  • {% endblock %} {% block content %} @@ -58,4 +59,21 @@ {% endif %} +
    +
    +

    Pintes

    +
    + Actions possibles : + +
    {% endblock %} diff --git a/gestion/urls.py b/gestion/urls.py index c05a330..3fb9e41 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -33,6 +33,7 @@ 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('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 c49854e..f87f020 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -13,7 +13,7 @@ import simplejson as json from dal import autocomplete from decimal import * -from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm +from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, CreatePinteForm from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte from preferences.models import PaymentMethod @@ -912,4 +912,25 @@ def allocate(pinte_pk, user): pinte.save() return True except Pinte.DoesNotExist: - return False \ No newline at end of file + return False + +@active_required +@login_required +@permission_required('gestion.add_pinte') +def create_pintes(request): + form = CreatePinteForm(request.POST or None) + if form.is_valid(): + ids = form.cleaned_data['ids'] + if ids != "": + ids = ids.split(" ") + else: + ids = range(form.cleaned_data['begin'], form.cleaned_data['end'] + 1) + i = 0 + for id in ids: + if not Pinte.objects.filter(pk=id).exists(): + new_pinte = Pinte(pk=int(id)) + new_pinte.save() + i += 1 + messages.success(request, str(i) + " pinte(s) a(ont) été ajoutée(s)") + return redirect(reverse('gestion:productsIndex')) + return render(request, "form.html", {"form": form, "form_title": "Ajouter des pintes", "form_button": "Ajouter"}) \ No newline at end of file