From 16622c4ba78cdedabe2d5611c32aa4ddf53cf80d Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 23 Dec 2018 23:55:27 +0100 Subject: [PATCH] Ajout du champ produit --- gestion/forms.py | 1 + gestion/templates/gestion/manage.html | 12 ++++++------ gestion/urls.py | 5 +++-- gestion/views.py | 26 ++++++++++++++++++-------- staticfiles/manage.js | 19 +++++++++++++------ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/gestion/forms.py b/gestion/forms.py index 325f1b2..01079a4 100644 --- a/gestion/forms.py +++ b/gestion/forms.py @@ -55,6 +55,7 @@ class SearchMenuForm(forms.Form): class GestionForm(forms.Form): client = forms.ModelChoiceField(queryset=User.objects.filter(is_active=True), required=True, label="Client", widget=autocomplete.ModelSelect2(url='users:active-users-autocomplete', attrs={'data-minimum-input-length':2})) + product = forms.ModelChoiceField(queryset=Product.objects.filter(is_active=True), required=True, label="Produit", widget=autocomplete.ModelSelect2(url='gestion:active-products-autocomplete', attrs={'data-minimum-input-length':2})) 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')) diff --git a/gestion/templates/gestion/manage.html b/gestion/templates/gestion/manage.html index ad9bec2..d08e42e 100644 --- a/gestion/templates/gestion/manage.html +++ b/gestion/templates/gestion/manage.html @@ -99,7 +99,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} @@ -112,7 +112,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} @@ -125,7 +125,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} @@ -138,7 +138,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} @@ -152,7 +152,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} @@ -166,7 +166,7 @@ {% if forloop.counter0|divisibleby:4 %} {% endif %} - + {% if forloop.counter|divisibleby:4 %} {% endif %} diff --git a/gestion/urls.py b/gestion/urls.py index bacf61f..2fa4368 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -24,9 +24,9 @@ urlpatterns = [ path('searchMenu', views.searchMenu, name="searchMenu"), path('editMenu/', views.edit_menu, name="editMenu"), path('menusList', views.menus_list, name="menusList"), - path('getMenu/', views.get_menu, name="getMenu"), + path('getMenu/', views.get_menu, name="getMenu"), path('swicthActivateMenu/', views.switch_activate_menu, name="switchActivateMenu"), - path('getProduct/', views.getProduct, name="getProduct"), + path('getProduct/', views.getProduct, name="getProduct"), path('order', views.order, name="order"), path('ranking', views.ranking, name="ranking"), path('searchProduct', views.searchProduct, name="searchProduct"), @@ -39,6 +39,7 @@ urlpatterns = [ path('release/', views.release, name="release"), path('pintesUserList', views.pintes_user_list, name="pintesUserList"), path('products-autocomplete', views.ProductsAutocomplete.as_view(), name="products-autocomplete"), + path('active-products-autocomplete', views.ActiveProductsAutocomplete.as_view(), name="active-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"), path('menus-autcomplete', views.MenusAutocomplete.as_view(), name="menus-autocomplete"), diff --git a/gestion/views.py b/gestion/views.py index 6eea6ca..727be04 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -420,14 +420,14 @@ def productProfile(request, pk): @active_required @login_required -def getProduct(request, barcode): +def getProduct(request, pk): """ Get :model:`gestion.Product` by barcode. Called by a js/JQuery script - ``barcode`` - The requested barcode + ``pk`` + The requested pk """ - product = Product.objects.get(barcode=barcode) + product = Product.objects.get(pk=pk) if product.category == Product.P_PRESSION: nb_pintes = 1 else: @@ -461,6 +461,16 @@ class ProductsAutocomplete(autocomplete.Select2QuerySetView): qs = qs.filter(name__istartswith=self.q) return qs +class ActiveProductsAutocomplete(autocomplete.Select2QuerySetView): + """ + Autocomplete view for active :model:`gestion.Product` + """ + def get_queryset(self): + qs = Product.objects.filter(is_active=True) + if self.q: + qs = qs.filter(name__istartswith=self.q) + return qs + ########## Kegs ########## @active_required @@ -851,14 +861,14 @@ def switch_activate_menu(request, pk): @active_required @login_required @permission_required('gestion.view_menu') -def get_menu(request, barcode): +def get_menu(request, pk): """ Search :model:`gestion.Menu` by barcode - ``barcode`` - The requested barcode + ``pk`` + The requested pk """ - menu = get_object_or_404(Menu, barcode=barcode) + menu = get_object_or_404(Menu, pk=pk) nb_pintes = 0 for article in menu.articles: if article.category == Product.P_PRESSION: diff --git a/staticfiles/manage.js b/staticfiles/manage.js index ad2691b..c4c176f 100644 --- a/staticfiles/manage.js +++ b/staticfiles/manage.js @@ -11,20 +11,19 @@ use_pinte_monitoring = false; function get_config(){ res = $.get("../preferences/getConfig", function(data){ - console.log(data.use_pinte_monitoring) use_pinte_monitoring = data.use_pinte_monitoring; }); } -function get_product(barcode){ - res = $.get("getProduct/" + barcode, function(data){ +function get_product(id){ + res = $.get("getProduct/" + id, function(data){ nbPintes += data.nb_pintes; add_product(data.pk, data.barcode, data.name, data.amount, data.needQuantityButton); }); } -function get_menu(barcode){ - res = $.get("getMenu/" + barcode, function(data){ +function get_menu(id){ + res = $.get("getMenu/" + id, function(data){ nbPintes += data.nb_pintes; add_menu(data.pk, data.barcode, data.name, data.amount, data.needQuantityButton); }); @@ -115,12 +114,15 @@ function updateMenuInput(a){ $(document).ready(function(){ get_config(); + $(".product").click(function(){ product = get_product($(this).attr('target')); }); + $(".menu").click(function(){ menu = get_menu($(this).attr('target')); - }) + }); + $("#id_client").on('change', function(){ id = $("#id_client").val(); $.get("/users/getUser/" + id, function(data){ @@ -133,6 +135,11 @@ $(document).ready(function(){ window.location.reload() }); }); + + $("#id_product").on('change', function(){ + product = get_product(parseInt($("#id_product").val())); + }); + $(".pay_button").click(function(){ if(use_pinte_monitoring){ message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?"