bug: search products balcao

This commit is contained in:
2025-01-04 18:06:05 -03:00
parent 0460040af3
commit 0ac4609ce6
11 changed files with 21 additions and 19 deletions

View File

@@ -9,10 +9,8 @@ from products.models import Product
from payments.models import Payments from payments.models import Payments
from typePay.models import TypePay from typePay.models import TypePay
@csrf_exempt
def listProductBalcao(request, comanda_id, search_product): def listProductBalcao(request, comanda_id, search_product):
print(search_product) if search_product == '*':
if len(search_product) == 0:
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate( produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'), quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade')) nome=F('product__name') ).order_by('-quantidade'))
@@ -24,7 +22,7 @@ def listProductBalcao(request, comanda_id, search_product):
if p.name == produto['nome']: if p.name == produto['nome']:
products_ordenados.append(p) products_ordenados.append(p)
return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products,'comanda_id':comanda_id}) return render(request, "htmx_components/htmx_list_products_balcao.html", {"products": products_ordenados,'comanda_id':comanda_id})
else: else:
product = search_product product = search_product
products = Product.objects.filter(name__icontains=product) products = Product.objects.filter(name__icontains=product)

View File

@@ -73,7 +73,7 @@
<h2 style="text-align: center;">Buscar Produto </h2> <h2 style="text-align: center;">Buscar Produto </h2>
<div class="grid-container"> <div class="grid-container">
<input <input
onkeypress="searchProduct()" oninput="searchProduct()"
type="text" type="text"
id="search-product" id="search-product"
name="search-product" name="search-product"
@@ -143,7 +143,7 @@
<ul> <ul>
</ul> </ul>
<footer> <footer>
<button class="secondary" hx-get="{% url 'paymentBalcao' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="backPage()"> <button class="secondary" hx-get="{% url 'paymentBalcao' comanda.id %} " hx-trigger="click" hx-swap="none" onclick="reloadPage()">
Comfimar Comfimar
</button> </button>

Binary file not shown.

View File

@@ -122,7 +122,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'pt-BR' LANGUAGE_CODE = 'pt-BR'
TIME_ZONE = 'UTC' TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True USE_I18N = True

View File

@@ -25,10 +25,10 @@ Produtos
<table id="list-products"> <table id="list-products">
<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;width: 20%;">Preço</th>
<th style="text-align: left;">Quantidade</th> <th style="text-align: left;">Quantidade</th>
<th style="text-align: left;">Categoria</th> <th style="text-align: left;">Categoria</th>
<th style="text-align: left;">Ações</th> <th style="text-align: left;width: 20%;">Ações</th>
</tr> </tr>
{% for product in products %} {% for product in products %}
@@ -40,7 +40,7 @@ Produtos
<td id="category-{{product.id}}" >{{product.category.name}}</td> <td id="category-{{product.id}}" >{{product.category.name}}</td>
<td> <td>
<div class="grid-buttons"> <div class="grid-buttons">
<button onclick="editProduct({{product.id}})" >📝 Editar</button> <h2 onclick="editProduct({{product.id}})" style="cursor: pointer;" >📝</h2>
<input type="hidden" id="h-category-{{product.id}}" value="{{ product.category.id }}"> <input type="hidden" id="h-category-{{product.id}}" value="{{ product.category.id }}">
<input type="hidden" id="description-{{product.id}}" value="{{ product.description }}"> <input type="hidden" id="description-{{product.id}}" value="{{ product.description }}">
@@ -49,9 +49,9 @@ Produtos
<input type="hidden" name="id-product" id="id-{{product.id}}" value="{{ product.id }}"> <input type="hidden" name="id-product" id="id-{{product.id}}" value="{{ product.id }}">
{% if product.active == True %} {% if product.active == True %}
<button style="background-color: red;">🚫 Desativar</button> <button style="background-color: rgba(255, 0, 0, 0);"></button>
{% else %} {% else %}
<button style="background-color: green;" >✅ Ativar</button> <button style="background-color: rgba(0, 128, 0, 0);" >🚫</button>
{% endif %} {% endif %}

View File

@@ -22,7 +22,7 @@ function imprimirFichas() {
font-size: 24px;} font-size: 24px;}
</style>`; </style>`;
const agora = new Date(); const agora = new Date();
var dateString = agora.getDay() + '/' + agora.getMonth() + '/' + agora.getFullYear() + ' - ' + agora.getHours() + ':' + agora.getMinutes()+' - Raul Rock Bar & Café'; var dateString = agora.getDate() + '/' +( agora.getMonth() + 1 )+ '/' + agora.getFullYear() + ' - ' + agora.getHours() + ':' + agora.getMinutes()+' - Raul Rock Bar & Café';
if (element) { if (element) {
var content = element.innerHTML; var content = element.innerHTML;
@@ -74,7 +74,8 @@ function updateTotal(){
function addProductBalcao() { function addProductBalcao() {
var productId = document.getElementById('0').innerText; var productId = document.getElementById('0').innerText;
var comandaId = document.getElementById('comanda0').innerText; var comandaId = document.getElementById('comanda0').innerText;
var qtd = document.getElementById('qtd-product').value; fieldQtd = document.getElementById('qtd-product');
var qtd = fieldQtd.value;
const url = `/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}/`; const url = `/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}/`;
fetch(url, { fetch(url, {
method: 'GET', method: 'GET',
@@ -90,6 +91,7 @@ function addProductBalcao() {
const imprimir = document.getElementById('imprimirFichas') const imprimir = document.getElementById('imprimirFichas')
receber.removeAttribute('disabled'); receber.removeAttribute('disabled');
imprimir.removeAttribute('disabled'); imprimir.removeAttribute('disabled');
fieldQtd.value = 1;
setTimeout(function() { setTimeout(function() {
updateTotal();}, 100); updateTotal();}, 100);
} }
@@ -130,7 +132,7 @@ function searchProduct() {
function time(){ function time(){
var search_product = document.getElementById('search-product').value.trim() var search_product = document.getElementById('search-product').value.trim()
var productListElement = document.getElementById("product-list"); var productListElement = document.getElementById("product-list");
if(search_product.length >= 1 ){ if(search_product.length == 0 ){search_product ='*';}
fetch(`/balcao/listProductBalcao/13/${search_product}`, { fetch(`/balcao/listProductBalcao/13/${search_product}`, {
method: 'GET',} method: 'GET',}
).then(function(response) { ).then(function(response) {
@@ -138,11 +140,12 @@ function searchProduct() {
}).then(function(text) { }).then(function(text) {
productListElement.innerHTML = text; productListElement.innerHTML = text;
})}} })}
} }
function addProductClick(productId, comandaId) { function addProductClick(productId, comandaId) {
var qtd = document.getElementById('qtd-product').value fieldQtd = document.getElementById('qtd-product');
var qtd = fieldQtd.value;
fetch(`/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}`, { fetch(`/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}`, {
method: 'GET', method: 'GET',
headers: { headers: {
@@ -160,6 +163,7 @@ function addProductClick(productId, comandaId) {
const imprimir = document.getElementById('imprimirFichas') const imprimir = document.getElementById('imprimirFichas')
receber.removeAttribute('disabled'); receber.removeAttribute('disabled');
imprimir.removeAttribute('disabled'); imprimir.removeAttribute('disabled');
fieldQtd.value = 1;
setTimeout(function() { setTimeout(function() {
updateTotal();}, 100); updateTotal();}, 100);

View File

@@ -72,8 +72,8 @@ input, textarea {
display: grid; display: grid;
grid-template-columns: repeat(1, 1fr); grid-template-columns: repeat(1, 1fr);
gap: 20px; gap: 20px;
max-width: 1000px; /* Define a largura máxima do grid */ max-width: 1300px;
margin: 0 auto; /* Centraliza o grid na página */ margin: 0 auto;
} }
.card { .card {