mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 21:45:41 +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
|
from products.models import Product
|
||||||
|
|
||||||
|
|
||||||
def listProduct(request):
|
def listProduct(request, comanda_id):
|
||||||
product = request.GET.get("search-product")
|
product = request.GET.get("search-product")
|
||||||
products = Product.objects.filter(name__icontains=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):
|
def addProduct(request, product_id, comanda_id):
|
||||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||||
product_comanda.save()
|
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 %}
|
{% load static %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% block 'title' %}
|
{% block 'title' %}
|
||||||
Comandas{% endblock %}
|
Comandas
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block 'head' %}
|
{% block 'head' %}
|
||||||
<link rel="stylesheet" href="{% static 'comandas/css/comandas.css' %}">
|
<link rel="stylesheet" href="{% static 'comandas/css/comandas.css' %}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block 'body' %}
|
{% block 'body' %}
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -17,12 +18,11 @@ Comandas{% endblock %}
|
|||||||
|
|
||||||
{% for comanda in comandas %}
|
{% for comanda in comandas %}
|
||||||
|
|
||||||
<div href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}" class="card">
|
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}"><div class="card" >
|
||||||
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.name}} </a> <br>
|
{{comanda.name}} <br>
|
||||||
<a href="{% url 'viewcomanda' %}?parametro={{ comanda.id }}">{{comanda.mesa}}</a>
|
{{comanda.mesa}}
|
||||||
|
|
||||||
|
</div></a>
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
@@ -41,11 +41,6 @@ Comandas{% endblock %}
|
|||||||
<option value="{{mesa.id}}">{{mesa.name}}</option>
|
<option value="{{mesa.id}}">{{mesa.name}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- <option value="opcao1">Opção 1</option>
|
|
||||||
<option value="opcao2">Opção 2</option>
|
|
||||||
<option value="opcao3" >Opção 3</option> -->
|
|
||||||
</select>
|
</select>
|
||||||
<button type="submit">Abrir</button>
|
<button type="submit">Abrir</button>
|
||||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Detalhes {{comanda.name}}
|
|||||||
{% block 'body' %}
|
{% block 'body' %}
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="grid-container">
|
<div class="grid-container" >
|
||||||
<button class="button" id="openModal">Adicionar Produto</button>
|
<button class="button" id="openModal">Adicionar Produto</button>
|
||||||
<!-- <p>{{comanda.id}}</p> -->
|
<!-- <p>{{comanda.id}}</p> -->
|
||||||
<p>{{comanda.name}}</p>
|
<p>{{comanda.name}}</p>
|
||||||
@@ -27,7 +27,7 @@ Detalhes {{comanda.name}}
|
|||||||
<p>{{comanda.dt_open}}</p>
|
<p>{{comanda.dt_open}}</p>
|
||||||
|
|
||||||
|
|
||||||
<table>
|
<table id="list-products-comanda">
|
||||||
<tr>
|
<tr>
|
||||||
<th style="text-align: left;">Produto</th>
|
<th style="text-align: left;">Produto</th>
|
||||||
<th style="text-align: left;">Preço</th>
|
<th style="text-align: left;">Preço</th>
|
||||||
@@ -58,12 +58,13 @@ Detalhes {{comanda.name}}
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<form id="productForm" >
|
<form id="productForm" >
|
||||||
<h2>Adicionar Produto <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button></h2>
|
<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">
|
<div id="product-list" class="grid-list-products">
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
|
|
||||||
<div class="card" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#product-list">
|
<div class="card" hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda">
|
||||||
{{product.name}}
|
{{product.name}} <br>
|
||||||
|
R$ {{product.price}}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ urlpatterns = [
|
|||||||
|
|
||||||
|
|
||||||
htmx_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('addProduct<int:product_id>/<int:comanda_id>/', htmx_views.addProduct, name='addProduct'),
|
||||||
# path('removeProduct/', views.removeProduct, name='removeProduct'),
|
# 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' %}
|
{% block 'body' %}
|
||||||
|
|
||||||
|
|
||||||
@@ -37,14 +36,22 @@ Produtos
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="modal" id="myModal">
|
<div class="modal" id="Modal-create-product">
|
||||||
<div class="modal-content">
|
<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>
|
<h2>Cadastro de Produto</h2>
|
||||||
<input type="text" id="productName" name="name" required placeholder="Nome"><br>
|
<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="0.01" id="productPrice" name="price" required placeholder="Preço"><br>
|
||||||
<input type="number" step="1" id="productqtd" name="qtd" required placeholder="Quantidade"><br>
|
<input type="number" step="1" id="productqtd" name="qtd" placeholder="Quantidade"><br>
|
||||||
<textarea id="productDescription" name="description" rows="4" required placeholder="Descrição"></textarea><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="submit">Salvar</button>
|
||||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
from django.urls import path, include
|
from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.products, name='products'),
|
path('', views.products, name='products'),
|
||||||
path('create_product', views.createProduct, name='create_product'),
|
path('create_product', views.createProduct, name='create_product'),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -11,11 +11,10 @@ def products(request):
|
|||||||
|
|
||||||
|
|
||||||
def createProduct(request):
|
def createProduct(request):
|
||||||
print(request.POST)
|
|
||||||
name = request.POST.get('name')
|
name = request.POST.get('name')
|
||||||
description = request.POST.get('description')
|
description = request.POST.get('description')
|
||||||
price = request.POST.get('price')
|
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 = Product(name=name, description=description, price=price, category=category)
|
||||||
product.save()
|
product.save()
|
||||||
return redirect('/products')
|
return redirect('/products')
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
|
{{co}}
|
||||||
|
|
||||||
<div class="card">
|
<div class="card" hx-get="{% url 'addProduct' product.id comanda_id %} " hx-trigger="click" hx-target="#list-products-comanda">
|
||||||
{{product.name}}
|
{{product.name}} <br>
|
||||||
|
R$ {{product.price}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endfor %}
|
{% 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 {
|
.card {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
height: 120px;
|
height: 120px;
|
||||||
background-color: #f2f2f2;
|
background-color: #c9ffbc;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
|
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
line-height: 120px; /* Centraliza o texto verticalmente */
|
line-height: 40px; /* Centraliza o texto verticalmente */
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #333;
|
color: #333;
|
||||||
transition: transform 0.2s;
|
transition: transform 0.2s;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card:hover {
|
.card:hover {
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
function openModal() {
|
function openModal() {
|
||||||
document.getElementById('myModal').style.display = 'block';
|
document.getElementById('Modal-create-product').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
document.getElementById('myModal').style.display = 'none';
|
document.getElementById('Modal-create-product').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 productName = document.getElementById('productName').value;
|
||||||
// const productPrice = document.getElementById('productPrice').value;
|
// const productPrice = document.getElementById('productPrice').value;
|
||||||
// const productDescription = document.getElementById('productDescription').value;
|
// const productDescription = document.getElementById('productDescription').value;
|
||||||
|
|
||||||
// closeModal();
|
// closeModal();
|
||||||
});
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
Reference in New Issue
Block a user