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

@@ -17,3 +17,13 @@ def addProduct(request, product_id, comanda_id):
for produto in consumo: for produto in consumo:
total += produto.product.price total += produto.product.price
return render(request, "htmx_components/htmx_list_products_in_comanda.html",{'consumo': consumo, 'total': total}) 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> <body>
<div class="grid-container" > <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.id}}</p> -->
<p>{{comanda.name}}</p> <div>
<p>{{comanda.mesa}}</p> <span>Nome: {{comanda.name}} | </span>
<p>{{comanda.dt_open}}</p> <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"> <table id="list-products-comanda">
@@ -38,6 +47,8 @@ Detalhes {{comanda.name}}
<tr> <tr>
<td>{{item.product.name}}</td> <td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</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> </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> <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/', htmx_views.listProduct, name='listProduct'),
path('listProduct/<int:comanda_id>/', 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('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'), # path('removeProduct/', views.removeProduct, name='removeProduct'),
] ]

Binary file not shown.

View File

@@ -126,6 +126,7 @@ USE_I18N = True
USE_TZ = True USE_TZ = True
DATE_FORMAT = 'd/m/Y - H:M'
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/ # https://docs.djangoproject.com/en/5.1/howto/static-files/

View File

@@ -8,6 +8,7 @@
<tr> <tr>
<td>{{item.product.name}}</td> <td>{{item.product.name}}</td>
<td>R$ {{item.product.price}}</td> <td>R$ {{item.product.price}}</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> </tr>
{% endfor %} {% endfor %}

View File

@@ -2,19 +2,29 @@ function openModal() {
document.getElementById('Modal-add-product').style.display = 'block'; document.getElementById('Modal-add-product').style.display = 'block';
} }
function open_remove_product_comanda() {
document.getElementById('remove-product-comanda').style.display = 'block';
}
function closeModal() { function closeModal() {
document.getElementById('Modal-add-product').style.display = 'none'; document.getElementById('Modal-add-product').style.display = 'none';
} }
function removeCloseModal() {
document.getElementById('remove-product-comanda').style.display = 'none';
}
document.getElementById('openModal').addEventListener('click', openModal); document.getElementById('openModal').addEventListener('click', openModal);
document.getElementById('productForm').addEventListener('submit', function(event) { document.getElementById('productForm').addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
// const productName = document.getElementById('productName').value;
// const productPrice = document.getElementById('productPrice').value;
// const productDescription = document.getElementById('productDescription').value;
// closeModal();
}); });