add botão (funcionando) remover produto da comanda

This commit is contained in:
2024-12-17 11:03:24 -03:00
parent 1e0e4d7b6f
commit 09b4f50a1b
10 changed files with 63 additions and 8 deletions

View File

@@ -14,6 +14,16 @@ def addProduct(request, product_id, comanda_id):
product_comanda.save()
consumo = ProductComanda.objects.filter(comanda=comanda_id)
total = 0
for produto in consumo:
total += produto.product.price
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})
def removeProductComanda(request, productComanda_id):
product_comanda = ProductComanda.objects.get(id=productComanda_id)
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
product_comanda.delete()
total = 0
for produto in consumo:
total += produto.product.price
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total})

View File

@@ -20,11 +20,20 @@ Detalhes {{comanda.name}}
<body>
<div class="grid-container" >
<button class="button" id="openModal">Adicionar Produto</button>
<div>
<button class="primary" id="openModal">Adicionar Produto</button>
<button id="pagarComanda">Pagar Comanda</button>
<button class="button" id="imprimirFichas">Imprimir Fichas</button>
</div>
<!-- <p>{{comanda.id}}</p> -->
<p>{{comanda.name}}</p>
<p>{{comanda.mesa}}</p>
<p>{{comanda.dt_open}}</p>
<div>
<span>Nome: {{comanda.name}} | </span>
<span>Mesa: {{comanda.mesa}}</span>
</div>
<p>Aberta em: {{comanda.dt_open|date:"D"}} {{comanda.dt_open|date:"d/m/Y - H:i"}}</p>
<table id="list-products-comanda">
@@ -38,6 +47,8 @@ Detalhes {{comanda.name}}
<tr>
<td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td>
<!-- <td><button id="open_remove_product_comanda" onclick="open_remove_product_comanda()">🗑️ Apagar</button></td> -->
<td><button hx-get="{% url 'removeProductComanda' item.id %} " hx-trigger="click" hx-target="#list-products-comanda" onclick="open_remove_product_comanda()">🗑️ Apagar</button></td>
</tr>
@@ -77,6 +88,27 @@ Detalhes {{comanda.name}}
<dialog id="remove-product-comanda" style="display: none;" >
<article>
<h2>Produto Excluido!</h2>
<h1></h1>
<p>
</p>
<ul>
</ul>
<footer>
<button class="secondary" onclick="removeCloseModal()">
OK
</button>
<!-- <button >Excluir</button> -->
</footer>
</article>
</dialog>
<script src="{% static 'comandas/js/viewcomanda.js' %}"></script>

View File

@@ -18,6 +18,7 @@ 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('removeProduct/', views.removeProduct, name='removeProduct'),
]