form create product | add product in comanda

This commit is contained in:
2024-12-15 18:53:16 -03:00
parent b74d817730
commit a840781473
17 changed files with 72 additions and 41 deletions

View File

@@ -4,12 +4,16 @@ from comandas.models import Comanda, ProductComanda
from products.models import Product
def listProduct(request):
def listProduct(request, comanda_id):
product = request.GET.get("search-product")
products = Product.objects.filter(name__icontains=product)
return render(request, "htmx_components/htmx_list_products.html", {"products": products})
return render(request, "htmx_components/htmx_list_products.html", {"products": products,'comanda_id':comanda_id})
def addProduct(request, product_id, comanda_id):
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
product_comanda.save()
return render(request, "htmx_components/htmx_add_product.html",)
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})

View File

@@ -2,13 +2,14 @@
{% load static %}
{% block 'title' %}
Comandas{% endblock %}
Comandas
{% endblock %}
{% block 'head' %}
<link rel="stylesheet" href="{% static 'comandas/css/comandas.css' %}">
{% endblock %}
{% block 'body' %}
<body>
@@ -17,12 +18,11 @@ Comandas{% endblock %}
{% for comanda in comandas %}
<div href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}" class="card">
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.name}} </a> <br>
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.mesa}}</a>
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}"><div class="card" >
{{comanda.name}} <br>
{{comanda.mesa}}
</div>
</div></a>
{% endfor %}
@@ -41,11 +41,6 @@ Comandas{% endblock %}
<option value="{{mesa.id}}">{{mesa.name}}</option>
{% endfor %}
<!-- <option value="opcao1">Opção 1</option>
<option value="opcao2">Opção 2</option>
<option value="opcao3" >Opção 3</option> -->
</select>
<button type="submit">Abrir</button>
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>

View File

@@ -19,7 +19,7 @@ Detalhes {{comanda.name}}
{% block 'body' %}
<body>
<div class="grid-container">
<div class="grid-container" >
<button class="button" id="openModal">Adicionar Produto</button>
<!-- <p>{{comanda.id}}</p> -->
<p>{{comanda.name}}</p>
@@ -27,7 +27,7 @@ Detalhes {{comanda.name}}
<p>{{comanda.dt_open}}</p>
<table>
<table id="list-products-comanda">
<tr>
<th style="text-align: left;">Produto</th>
<th style="text-align: left;">Preço</th>
@@ -58,12 +58,13 @@ Detalhes {{comanda.name}}
<div class="modal-content">
<form id="productForm" >
<h2>Adicionar Produto <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button></h2>
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'listProduct' %}" hx-trigger="keyup" hx-target="#product-list"><br>
<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="product-list" class="grid-list-products">
{% for product in products %}
<div class="card" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#product-list">
{{product.name}}
<div class="card" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
{{product.name}} <br>
R$ {{product.price}}
</div>
{% endfor %}
</div>

View File

@@ -15,7 +15,8 @@ urlpatterns = [
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('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
# path('removeProduct/', views.removeProduct, name='removeProduct'),