ordem add produtos na comanda

This commit is contained in:
2025-01-07 20:00:06 -03:00
parent b2641691fe
commit 6633110140
8 changed files with 37 additions and 23 deletions

View File

@@ -8,7 +8,11 @@ from typePay.models import TypePay
def listProduct(request, comanda_id):
product = request.GET.get("search-product")
products = Product.objects.filter(name__icontains=product)
allProducts = Product.objects.filter(name__icontains=product)
products = []
for p in allProducts:
if p.active == True:
products.append(p)
return render(request, "htmx_components/htmx_list_products.html", {"products": products,'comanda_id':comanda_id})
def addProduct(request, product_id, comanda_id):

View File

@@ -21,7 +21,7 @@ Detalhes {{comanda.name}}
<body>
<div class="grid-container" >
<div>
<button class="primary" id="openModal"
<button class="primary" id="openModal" onclick="openModal()"
{% if comanda.status != 'OPEN'%}
disabled
{% endif %}

View File

@@ -1,4 +1,5 @@
from django.shortcuts import render, redirect
from django.db.models import Count, F
from comandas.models import Comanda, ProductComanda
from products.models import Product
@@ -17,12 +18,23 @@ def viewComanda(request):
comanda_id = int(id)
comanda = Comanda.objects.get(id=comanda_id)
consumo = ProductComanda.objects.filter(comanda=comanda_id)
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade'))
products = Product.objects.all()
products_ordenados = []
for produto in produtos_mais_vendidos:
for p in products:
if p.name == produto['nome'] and p.active == True:
products_ordenados.append(p)
total = 0
for produto in consumo:
total += produto.product.price
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products})
return render(request, 'viewcomanda.html', {'comanda': comanda, 'consumo': consumo, 'total': total, 'products': products_ordenados})