From 4060a22c50f7292ea1c4a4d39f9e48eabec32d60 Mon Sep 17 00:00:00 2001 From: Yoann Pietri Date: Sat, 5 Oct 2019 19:26:56 +0200 Subject: [PATCH] Improve search and fix keg edition --- gestion/views.py | 2 +- search/templates/search/search.html | 43 +++++++++++++++++++++++++++++ search/views.py | 6 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/gestion/views.py b/gestion/views.py index 810d5bf..f6213c2 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -626,7 +626,7 @@ def editKeg(request, pk): keg.demi.name = "Demi " + name keg.demi.save() if(keg.galopin): - keg.galopin.deg = deg + keg.galopin.deg = keg.deg keg.galopin.amount = ceil(2.5 * pinte_price)/10 keg.galopin.name = "Galopin " + name keg.galopin.save() diff --git a/search/templates/search/search.html b/search/templates/search/search.html index 088ce56..195a0e1 100644 --- a/search/templates/search/search.html +++ b/search/templates/search/search.html @@ -8,6 +8,9 @@ {% if perms.gestion.view_product %}
  • Produits ({{products.count}})
  • {% endif %} + {% if perms.gestion.view_consumptionhistory %} +
  • Dernières transactions ({{last_consumptions.count}})
  • + {% endif %} {% if perms.gestion.view_keg %}
  • Fûts ({{kegs.count}})
  • {% endif %} @@ -104,6 +107,46 @@ {% endif %} +{% if perms.auth.view_consumptionhistory %} +
    +
    +

    Résultats dans les dernières transactions ({{last_consumptions.count}} résultat{% if last_consumptions.count != 1 %}s{% endif %})

    +
    +
    + {% if last_consumptions.count %} +
    + + + + + + + + + + + + + {% for consumption in last_consumptions %} + + + + + + + + + {%endfor%} + +
    ProduitQuantitéUtilisateurDateType de paiementAdministration
    {{consumption.product}}{{consumption.quantity}}{{consumption.customer}}{{consumption.date}}{{consumption.payment_method}}{% if perms.gestion.delete_consumptionhistory %} Annuler{% endif %}
    +
    + {% else %} + Aucun résultat n'a pu être trouvé. + {% endif %} +
    +
    +{% endif %} + {% if perms.gestion.view_keg %}
    diff --git a/search/views.py b/search/views.py index 49306ee..80fbc0d 100644 --- a/search/views.py +++ b/search/views.py @@ -4,7 +4,7 @@ from django.contrib.auth.models import User, Group from django.contrib.auth.decorators import login_required from coopeV3.acl import active_required -from gestion.models import Product, Menu, Keg +from gestion.models import Product, Menu, Keg, ConsumptionHistory @active_required @login_required @@ -13,13 +13,15 @@ def search(request): if q: users = User.objects.filter(Q(username__icontains=q) | Q(first_name__icontains=q) | Q(last_name__icontains=q)) products = Product.objects.filter(name__icontains=q) + last_consumptions = ConsumptionHistory.objects.select_related('product').filter(product__name__icontains=q).order_by('-date')[:10] kegs = Keg.objects.filter(name__icontains=q) menus = Menu.objects.filter(name__icontains=q) groups = Group.objects.filter(name__icontains=q) else: users = User.objects.none() products = Product.objects.none() + lats_consumptions = ConsumptionHistory.objects.none() kegs = Keg.objects.none() menus = Menu.objects.none() groups = Group.objects.none() - return render(request, "search/search.html", {"q": q, "users": users, "products": products, "kegs": kegs, "menus": menus, "groups": groups}) \ No newline at end of file + return render(request, "search/search.html", {"q": q, "users": users, "products": products, "last_consumptions": last_consumptions, "kegs": kegs, "menus": menus, "groups": groups})