3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-22 03:13:12 +00:00

Merge branch 'product_autocomplete_manage' into dev

Close #20
This commit is contained in:
Yoann Pétri 2018-12-23 23:55:50 +01:00
commit db2c82cfe7
5 changed files with 41 additions and 22 deletions

View file

@ -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'))

View file

@ -99,7 +99,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}
@ -112,7 +112,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}
@ -125,7 +125,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}
@ -138,7 +138,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}
@ -152,7 +152,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="product {% if product.adherentRequired %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}
@ -166,7 +166,7 @@
{% if forloop.counter0|divisibleby:4 %}
<tr style="text-align:center">
{% endif %}
<td><button class="menu {% if product.adherent_required %}special{% endif%}" target="{{product.barcode}}">{{product.name}}</button></td>
<td><button class="menu {% if product.adherent_required %}special{% endif%}" target="{{product.pk}}">{{product.name}}</button></td>
{% if forloop.counter|divisibleby:4 %}
</tr>
{% endif %}

View file

@ -24,9 +24,9 @@ urlpatterns = [
path('searchMenu', views.searchMenu, name="searchMenu"),
path('editMenu/<int:pk>', views.edit_menu, name="editMenu"),
path('menusList', views.menus_list, name="menusList"),
path('getMenu/<str:barcode>', views.get_menu, name="getMenu"),
path('getMenu/<int:pk>', views.get_menu, name="getMenu"),
path('swicthActivateMenu/<int:pk>', views.switch_activate_menu, name="switchActivateMenu"),
path('getProduct/<str:barcode>', views.getProduct, name="getProduct"),
path('getProduct/<int:pk>', 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/<int:pinte_pk>', 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"),

View file

@ -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:

View file

@ -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 ?"