mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +00:00
refactor:alteração modal de add product na comanda
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@ from django.shortcuts import render, redirect
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
from orders.models import Order
|
||||
from products.models import Product
|
||||
from payments.models import Payments
|
||||
from payments.models import Payments, somar
|
||||
from typePay.models import TypePay
|
||||
from gestaoRaul.decorators import group_required
|
||||
from websocket_client.websocketClient import enviar_mensagem
|
||||
@@ -29,80 +29,6 @@ from asgiref.sync import async_to_sync
|
||||
# print(f"Erro ao enviar mensagem via websocket: {e}")
|
||||
|
||||
|
||||
def somar(consumo:ProductComanda, comanda:Comanda):
|
||||
parcial = Payments.objects.filter(comanda=comanda)
|
||||
totalParcial = Decimal(0)
|
||||
total:Decimal = Decimal(0)
|
||||
for p in parcial:
|
||||
totalParcial += p.value
|
||||
for produto in consumo:
|
||||
total += Decimal(produto.product.price)
|
||||
valores = {
|
||||
'total':total,
|
||||
'parcial':totalParcial,
|
||||
'taxa': round(total * Decimal(0.1), 2),
|
||||
'totalSemTaxa':total - totalParcial,
|
||||
'totalComTaxa': round((total - totalParcial)+(total * Decimal(0.1)),2)
|
||||
}
|
||||
return valores
|
||||
|
||||
def listProduct(request, comanda_id):
|
||||
product = request.GET.get("search-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/comandas/htmx_list_products.html", {"products": products,'comanda_id':comanda_id})
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
config = {
|
||||
'taxa': False
|
||||
}
|
||||
obs = request.GET.get("obs")
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
product = Product.objects.get(id=product_id)
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
parcial = Payments.objects.filter(comanda=comanda)
|
||||
if product.cuisine == True:
|
||||
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
||||
order.save()
|
||||
msg = JsonResponse({
|
||||
'type': 'broadcast',
|
||||
'message': f"""
|
||||
<div class="m-card" id="m-card-{order.id}">
|
||||
<h4>{product.name}</h4>
|
||||
<h4 id="obs-{order.id}"> {order.obs}</h4>
|
||||
<h4>{comanda.name} - {comanda.mesa.name}</h4>
|
||||
<h4> {order.queue.strftime("%d/%m/%Y - %H:%M")}</h4>
|
||||
<h4> Atendente: {comanda.user.first_name}</h4>
|
||||
<form method="path" action="/pedidos/preparing/{order.id}/">
|
||||
<button class="btn-primary" type="submit">Preparar</button>
|
||||
</form>
|
||||
</div>
|
||||
""",
|
||||
'local':'cozinha',
|
||||
'tipo':'add',
|
||||
'id':order.id,
|
||||
'speak': f'Novo pedido! {product.name}, para {comanda.name}.'
|
||||
})
|
||||
try:
|
||||
# Chama a função async dentro da view normal
|
||||
async_to_sync(enviar_mensagem)(mensagem)
|
||||
|
||||
# return JsonResponse({"status": "Mensagem enviada com sucesso"})
|
||||
|
||||
except Exception as e:
|
||||
print("Erro add product websocket: ",e)
|
||||
# return JsonResponse({"status": "Erro", "erro": str(e)}, status=500)
|
||||
# asyncio.run(enviar_mensagem(msg))
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
valores = somar(consumo,comanda)
|
||||
|
||||
return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'config':config, 'valores':valores,'parcials':parcial,'consumo': consumo,'comanda':comanda})
|
||||
|
||||
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
|
||||
@@ -13,6 +13,16 @@ Detalhes {{comanda.name}}
|
||||
|
||||
{% block 'head' %}
|
||||
<link rel="stylesheet" href="{% static 'comandas/css/viewcomanda.css' %}">
|
||||
<style>
|
||||
.swal2-popup {
|
||||
position: relative; /* Necessário para o posicionamento absoluto do botão */
|
||||
}
|
||||
.posi {
|
||||
position: absolute !important;
|
||||
top: 0.5em;
|
||||
right: 0.5em;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -22,7 +32,7 @@ Detalhes {{comanda.name}}
|
||||
<input hidden id="id-temp" type="number">
|
||||
<div class="grid-container" >
|
||||
<div style="display: flex;padding: 5px;gap:8px">
|
||||
<button class="btn-primary" id="openModal" onclick="openModal()" popovertarget="addProduct"
|
||||
<button class="btn-primary" id="openModal" onclick="openModal()"
|
||||
{% if comanda.status != 'OPEN'%}
|
||||
disabled
|
||||
{% endif %}
|
||||
@@ -71,6 +81,7 @@ Detalhes {{comanda.name}}
|
||||
</div>
|
||||
<div>
|
||||
<input hidden type="text" id="h-mesaId" value="{{comanda.mesa.id}}">
|
||||
<input hidden type="text" id="id-comanda" value="{{comanda.id}}">
|
||||
<span id="name-comanda">Nome: {{comanda.name}} | </span>
|
||||
<span id="mesa-comanda">Local: {{comanda.mesa}}</span>
|
||||
|
||||
@@ -173,17 +184,13 @@ Detalhes {{comanda.name}}
|
||||
|
||||
|
||||
|
||||
<div id="addProduct" popover class="popover">
|
||||
<div id="toast-add" class="toast-add">
|
||||
<p id="toast-message-add"></p>
|
||||
</div>
|
||||
<form id="productForm" >
|
||||
<div style="display: flex;justify-content: space-between;">
|
||||
<h2>Adicionar Produto</h2> <img class="close" src="{% static 'midia/icons/close-circle.svg' %}" onclick="closeModal()">
|
||||
</div>
|
||||
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'listProduct' comanda.id %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
<div id="addProduct" class="popover">
|
||||
<!-- <div id="productForm" > -->
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="text" oninput="searchProduct()" id="search-product" name="search-product" placeholder="Buscar Produto" ><br>
|
||||
<div id="product-list" class="grid-list-products">
|
||||
|
||||
{% for product in products %}
|
||||
|
||||
<div class="card-product" onclick="addProductComanda({{product.id}}, {{comanda.id}}, '{{product.cuisine}}')" >
|
||||
@@ -192,7 +199,7 @@ Detalhes {{comanda.name}}
|
||||
</div >
|
||||
{% endfor %}
|
||||
</div>
|
||||
</form>
|
||||
<!-- </div> -->
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ urlpatterns = [
|
||||
path('notificacao/', views.notificacao, name='notificacao'),
|
||||
path('editOrders/<int:productComanda_id>/<str:obs>', views.editOrders, name='editOrders'),
|
||||
path('closeComanda/<int:comanda_id>/', views.closeComanda, name='closeComanda'),
|
||||
path('listProduct/<int:comanda_id>/<str:product>/', views.listProduct, name='listProduct'),
|
||||
path('product=<int:product_id>/comanda=<int:comanda_id>/', views.addProduct, name='addProduct'),
|
||||
|
||||
|
||||
|
||||
@@ -20,9 +22,6 @@ urlpatterns = [
|
||||
|
||||
|
||||
htmx_urlpatterns = [
|
||||
# path('listProduct/', htmx_views.listProduct, name='listProduct'),
|
||||
path('listProduct/<int:comanda_id>/', htmx_views.listProduct, name='listProduct'),
|
||||
path('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
|
||||
path('removeProductComanda<int:productComanda_id>/', htmx_views.removeProductComanda, name='removeProductComanda'),
|
||||
path('reopenComanda<int:comanda_id>/', htmx_views.reopenComanda, name='reopenComanda'),
|
||||
path('paymentComanda<int:comanda_id>/', htmx_views.paymentComanda, name='paymentComanda'),
|
||||
|
||||
@@ -23,23 +23,6 @@ def comandas(request):
|
||||
return render(request, 'comandas.html', {'comandas': comandas, 'mesas': mesas})
|
||||
|
||||
|
||||
# def somar(consumo:ProductComanda, comanda:Comanda):
|
||||
# parcial = Payments.objects.filter(comanda=comanda)
|
||||
# totalParcial = Decimal(0)
|
||||
# total:Decimal = Decimal(0)
|
||||
# for p in parcial:
|
||||
# totalParcial += p.value
|
||||
# for produto in consumo:
|
||||
# total += Decimal(produto.product.price)
|
||||
# valores = {
|
||||
# 'total':total,
|
||||
# 'parcial':totalParcial,
|
||||
# 'taxa': round(total * Decimal(0.1), 2),
|
||||
# 'totalSemTaxa':total - totalParcial,
|
||||
# 'totalComTaxa': round((total - totalParcial)+(total * Decimal(0.1)),2)
|
||||
# }
|
||||
# return valores
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
def viewComanda(request):
|
||||
config = {
|
||||
@@ -166,4 +149,62 @@ def closeComanda(request, comanda_id):
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
comanda.status = "PAYING"
|
||||
comanda.save()
|
||||
return JsonResponse({'status': 'ok', 'obs':'order.obs'})
|
||||
return JsonResponse({'status': 'ok', 'obs':'order.obs'})
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
config = {
|
||||
'taxa': False
|
||||
}
|
||||
obs = request.GET.get("obs")
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
product = Product.objects.get(id=product_id)
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
parcial = Payments.objects.filter(comanda=comanda)
|
||||
if product.cuisine == True:
|
||||
order = Order(id_comanda=comanda, id_product=product, productComanda=product_comanda, obs='')
|
||||
order.save()
|
||||
msg = JsonResponse({
|
||||
'type': 'broadcast',
|
||||
'message': f"""
|
||||
<div class="m-card" id="m-card-{order.id}">
|
||||
<h4>{product.name}</h4>
|
||||
<h4 id="obs-{order.id}"> {order.obs}</h4>
|
||||
<h4>{comanda.name} - {comanda.mesa.name}</h4>
|
||||
<h4> {order.queue.strftime("%d/%m/%Y - %H:%M")}</h4>
|
||||
<h4> Atendente: {comanda.user.first_name}</h4>
|
||||
<form method="path" action="/pedidos/preparing/{order.id}/">
|
||||
<button class="btn-primary" type="submit">Preparar</button>
|
||||
</form>
|
||||
</div>
|
||||
""",
|
||||
'local':'cozinha',
|
||||
'tipo':'add',
|
||||
'id':order.id,
|
||||
'speak': f'Novo pedido! {product.name}, para {comanda.name}.'
|
||||
})
|
||||
try:
|
||||
# Chama a função async dentro da view normal
|
||||
async_to_sync(enviar_mensagem)(mensagem)
|
||||
|
||||
# return JsonResponse({"status": "Mensagem enviada com sucesso"})
|
||||
|
||||
except Exception as e:
|
||||
print("Erro add product websocket: ",e)
|
||||
# return JsonResponse({"status": "Erro", "erro": str(e)}, status=500)
|
||||
# asyncio.run(enviar_mensagem(msg))
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
valores = somar(consumo,comanda)
|
||||
|
||||
return render(request, "htmx_components/comandas/htmx_list_products_in_comanda.html",{'config':config, 'valores':valores,'parcials':parcial,'consumo': consumo,'comanda':comanda})
|
||||
|
||||
|
||||
|
||||
def listProduct(request, comanda_id, 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/comandas/htmx_list_products.html", {"products": products,'comanda_id':comanda_id})
|
||||
Reference in New Issue
Block a user