mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 05:25:40 +00:00
feat: gerenciamento quantidade product
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -30,6 +30,8 @@ def addProductBalcao(request, product_id, comanda_id, qtd):
|
||||
for i in range(qtd):
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
Product.subStock(Product.objects.get(id=product_id), qtd)
|
||||
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
@@ -42,6 +44,7 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
||||
for i in range(qtd):
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
Product.subStock(Product.objects.get(id=product_id), qtd)
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
@@ -53,6 +56,8 @@ def removeProductBalcao(request, productComanda_id):
|
||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
||||
product_comanda.delete()
|
||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||
|
||||
total = 0
|
||||
for produto in consumo:
|
||||
total += produto.product.price
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -45,6 +45,8 @@ def removeProductComanda(request, productComanda_id):
|
||||
if product_comanda.product.cuisine == True:
|
||||
order = Order.objects.get(productComanda=product_comanda)
|
||||
product_comanda.delete()
|
||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||
|
||||
msg = JsonResponse({
|
||||
'type': 'broadcast',
|
||||
'message': 'Atenção! Pedido cancelado',
|
||||
@@ -59,6 +61,7 @@ def removeProductComanda(request, productComanda_id):
|
||||
valores = somar(consumo,comanda)
|
||||
else:
|
||||
product_comanda.delete()
|
||||
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||
valores = somar(consumo,comanda)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ Detalhes {{comanda.name}}
|
||||
<input hidden id="id-temp" type="number">
|
||||
<div class="grid-container" >
|
||||
<div style="display: flex;padding: 5px;gap:8px">
|
||||
<button class="btn-primary" id="openModal" onclick="openModal()"
|
||||
<button class="btn-primary" id="openModal" onclick="modalAddProduct()"
|
||||
{% if comanda.status != 'OPEN'%}
|
||||
disabled
|
||||
{% endif %}
|
||||
|
||||
Binary file not shown.
@@ -141,13 +141,13 @@ def closeComanda(request, comanda_id):
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
def addProduct(request, product_id, comanda_id):
|
||||
print('chamouuuuuuuuuuu')
|
||||
config = {
|
||||
'taxa': False
|
||||
}
|
||||
obs = request.GET.get("obs")
|
||||
product_comanda = ProductComanda(comanda_id=comanda_id, product_id=product_id)
|
||||
product_comanda.save()
|
||||
Product.subStock(Product.objects.get(id=product_id), 1)
|
||||
product = Product.objects.get(id=product_id)
|
||||
comanda = Comanda.objects.get(id=comanda_id)
|
||||
parcial = Payments.objects.filter(comanda=comanda)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -106,24 +106,24 @@ WSGI_APPLICATION = 'gestaoRaul.wsgi.application'
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||
|
||||
#DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.sqlite3',
|
||||
# 'NAME': BASE_DIR / 'db.sqlite3',
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': DB_ENGINE,
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': DB_PORT,
|
||||
}
|
||||
}
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE': DB_ENGINE,
|
||||
# 'NAME': DB_NAME,
|
||||
# 'USER': DB_USER,
|
||||
# 'PASSWORD': DB_PASSWORD,
|
||||
# 'HOST': DB_HOST,
|
||||
# 'PORT': DB_PORT,
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# Password validation
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,4 +16,12 @@ class Product(models.Model):
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.id} - {self.name} - {self.price} - {self.category} - {self.cuisine} - {self.active} "
|
||||
return f"{self.name}"
|
||||
|
||||
def subStock(self, qtd):
|
||||
self.quantity -= qtd
|
||||
self.save()
|
||||
|
||||
def addStock(self, qtd):
|
||||
self.quantity += qtd
|
||||
self.save()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
from django.db.models import Q
|
||||
from django.db.models import Q, Count, F
|
||||
|
||||
|
||||
from categories.models import Categories
|
||||
from comandas.models import ProductComanda
|
||||
from products.models import Product
|
||||
from gestaoRaul.decorators import group_required
|
||||
|
||||
@@ -65,6 +67,10 @@ def editProduct(request, productId):
|
||||
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||
|
||||
def createJson(request):
|
||||
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
|
||||
quantidade=Count('product'),
|
||||
nome=F('product__name') ).order_by('-quantidade'))
|
||||
|
||||
products = Product.objects.filter(active=True).exclude(
|
||||
category__name__in=['Insumos',
|
||||
'Adicional',
|
||||
@@ -76,8 +82,21 @@ def createJson(request):
|
||||
'Cigarros',
|
||||
'Outros']
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
products_ordenados = []
|
||||
for produto in produtos_mais_vendidos:
|
||||
for p in products:
|
||||
if p.name == produto['nome']:
|
||||
products_ordenados.append(p)
|
||||
|
||||
|
||||
|
||||
|
||||
product_list = []
|
||||
for product in products:
|
||||
for product in products_ordenados:
|
||||
product_data = {
|
||||
"id": product.id,
|
||||
"name": product.name,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
async function openModal() {
|
||||
async function modalAddProduct() {
|
||||
var htmlModal = document.getElementById('addProduct').innerHTML
|
||||
htmlModal = htmlModal.replace('search-product','search-product-modal')
|
||||
htmlModal = htmlModal.replace('product-list','product-list-modal')
|
||||
@@ -364,15 +364,7 @@ async function addProductComanda(productId, comandaId, cuisine) {
|
||||
throw new Error('Token de segurança não encontrado');
|
||||
}
|
||||
|
||||
// if (cuisine === 'ggg') {
|
||||
// openModalObs();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Mostra estado de carregamento
|
||||
Swal.update({
|
||||
title: '<span style="color: white;">Adicionando produto...</span>',
|
||||
});
|
||||
|
||||
// Requisição POST
|
||||
const response = await fetch(`/comandas/product=${productId}/comanda=${comandaId}/`, {
|
||||
@@ -403,6 +395,7 @@ async function addProductComanda(productId, comandaId, cuisine) {
|
||||
}
|
||||
|
||||
const result = await response.text();
|
||||
console.log(response);
|
||||
|
||||
// Atualiza a lista de produtos
|
||||
const listElement = document.getElementById("list-products-comanda");
|
||||
@@ -410,17 +403,11 @@ async function addProductComanda(productId, comandaId, cuisine) {
|
||||
listElement.innerHTML = result;
|
||||
}
|
||||
|
||||
// if (cuisine === 'True') {
|
||||
// openModalObs();
|
||||
// return;
|
||||
// }
|
||||
|
||||
Swal.update({
|
||||
title: '<span style="color: green;">✅ Produto adicionado!</span>',
|
||||
});
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
Swal.update({
|
||||
title: '<span style="color: white;">Adicionar Produto</span>'
|
||||
});
|
||||
}, 2500);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erro:', error);
|
||||
|
||||
Reference in New Issue
Block a user