mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 05:25:40 +00:00
form create product | add product in comanda
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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})
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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'),
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,7 +14,6 @@ Produtos
|
||||
|
||||
|
||||
|
||||
|
||||
{% block 'body' %}
|
||||
|
||||
|
||||
@@ -37,14 +36,22 @@ Produtos
|
||||
|
||||
|
||||
|
||||
<div class="modal" id="myModal">
|
||||
<div class="modal" id="Modal-create-product">
|
||||
<div class="modal-content">
|
||||
<form id="productForm" method="post" action="{% url 'create_product' %}">
|
||||
<form action="{% url 'create_product' %}" id="productForm" method="post" >
|
||||
{% csrf_token %}
|
||||
<h2>Cadastro de Produto</h2>
|
||||
<input type="text" id="productName" name="name" required placeholder="Nome"><br>
|
||||
<input type="number" step="0.01" id="productPrice" name="price" required placeholder="Preço"><br>
|
||||
<input type="number" step="1" id="productqtd" name="qtd" required placeholder="Quantidade"><br>
|
||||
<textarea id="productDescription" name="description" rows="4" required placeholder="Descrição"></textarea><br>
|
||||
<input type="number" step="1" id="productqtd" name="qtd" placeholder="Quantidade"><br>
|
||||
<select name="select-categorie" >
|
||||
|
||||
{% for categorie in categories %}
|
||||
<option value="{{categorie.id}}">{{categorie.name}}</option>
|
||||
{% endfor %}
|
||||
|
||||
</select>
|
||||
<textarea id="productDescription" name="description" rows="4" placeholder="Descrição"></textarea><br>
|
||||
<button type="submit">Salvar</button>
|
||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||
</form>
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
|
||||
from django.urls import path, include
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.products, name='products'),
|
||||
path('create_product', views.createProduct, name='create_product'),
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
@@ -11,11 +11,10 @@ def products(request):
|
||||
|
||||
|
||||
def createProduct(request):
|
||||
print(request.POST)
|
||||
name = request.POST.get('name')
|
||||
description = request.POST.get('description')
|
||||
price = request.POST.get('price')
|
||||
category = request.POST.get('category')
|
||||
category = Categories.objects.get(id = int(request.POST.get('select-categorie')))
|
||||
product = Product(name=name, description=description, price=price, category=category)
|
||||
product.save()
|
||||
return redirect('/products')
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
|
||||
{% for product in products %}
|
||||
{{co}}
|
||||
|
||||
<div class="card">
|
||||
{{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 %}
|
||||
@@ -11,3 +13,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<tr>
|
||||
<th style="text-align: left;">Produto</th>
|
||||
<th style="text-align: left;">Preço</th>
|
||||
</tr>
|
||||
|
||||
{% for item in consumo%}
|
||||
|
||||
<tr>
|
||||
<td>{{item.product.name}}</td>
|
||||
<td>R$ {{item.product.price}}</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" style="text-align: center;">Total R$ {{total}}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@@ -17,15 +17,16 @@
|
||||
.card {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
background-color: #f2f2f2;
|
||||
background-color: #c9ffbc;
|
||||
border-radius: 15px;
|
||||
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
|
||||
text-align: center;
|
||||
line-height: 120px; /* Centraliza o texto verticalmente */
|
||||
line-height: 40px; /* Centraliza o texto verticalmente */
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
transition: transform 0.2s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
function openModal() {
|
||||
document.getElementById('myModal').style.display = 'block';
|
||||
document.getElementById('Modal-create-product').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
document.getElementById('myModal').style.display = 'none';
|
||||
document.getElementById('Modal-create-product').style.display = 'none';
|
||||
}
|
||||
|
||||
document.getElementById('openModal').addEventListener('click', openModal);
|
||||
|
||||
document.getElementById('productForm').addEventListener('submit', function(event) {
|
||||
event.preventDefault();
|
||||
// document.getElementById('productForm').addEventListener('submit', function(event) {
|
||||
// event.preventDefault();
|
||||
|
||||
// const productName = document.getElementById('productName').value;
|
||||
// const productPrice = document.getElementById('productPrice').value;
|
||||
// const productDescription = document.getElementById('productDescription').value;
|
||||
|
||||
// closeModal();
|
||||
});
|
||||
// }
|
||||
// );
|
||||
|
||||
Reference in New Issue
Block a user