mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +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):
|
for i in range(qtd):
|
||||||
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()
|
||||||
|
Product.subStock(Product.objects.get(id=product_id), qtd)
|
||||||
|
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
@@ -42,6 +44,7 @@ def addProductBalcaoTeclado(request, product_id, comanda_id, qtd):
|
|||||||
for i in range(qtd):
|
for i in range(qtd):
|
||||||
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()
|
||||||
|
Product.subStock(Product.objects.get(id=product_id), qtd)
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
consumo = ProductComanda.objects.filter(comanda=comanda_id)
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
@@ -53,6 +56,8 @@ def removeProductBalcao(request, productComanda_id):
|
|||||||
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
product_comanda = ProductComanda.objects.get(id=productComanda_id)
|
||||||
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
consumo = ProductComanda.objects.filter(comanda=product_comanda.comanda)
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
|
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
for produto in consumo:
|
for produto in consumo:
|
||||||
total += produto.product.price
|
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:
|
if product_comanda.product.cuisine == True:
|
||||||
order = Order.objects.get(productComanda=product_comanda)
|
order = Order.objects.get(productComanda=product_comanda)
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
|
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||||
|
|
||||||
msg = JsonResponse({
|
msg = JsonResponse({
|
||||||
'type': 'broadcast',
|
'type': 'broadcast',
|
||||||
'message': 'Atenção! Pedido cancelado',
|
'message': 'Atenção! Pedido cancelado',
|
||||||
@@ -59,6 +61,7 @@ def removeProductComanda(request, productComanda_id):
|
|||||||
valores = somar(consumo,comanda)
|
valores = somar(consumo,comanda)
|
||||||
else:
|
else:
|
||||||
product_comanda.delete()
|
product_comanda.delete()
|
||||||
|
Product.addStock(Product.objects.get(id=product_comanda.product.id), 1)
|
||||||
consumo = ProductComanda.objects.filter(comanda=comanda)
|
consumo = ProductComanda.objects.filter(comanda=comanda)
|
||||||
valores = somar(consumo,comanda)
|
valores = somar(consumo,comanda)
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ Detalhes {{comanda.name}}
|
|||||||
<input hidden id="id-temp" type="number">
|
<input hidden id="id-temp" type="number">
|
||||||
<div class="grid-container" >
|
<div class="grid-container" >
|
||||||
<div style="display: flex;padding: 5px;gap:8px">
|
<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'%}
|
{% if comanda.status != 'OPEN'%}
|
||||||
disabled
|
disabled
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Binary file not shown.
@@ -141,13 +141,13 @@ def closeComanda(request, comanda_id):
|
|||||||
|
|
||||||
@group_required(groupName='Garçom')
|
@group_required(groupName='Garçom')
|
||||||
def addProduct(request, product_id, comanda_id):
|
def addProduct(request, product_id, comanda_id):
|
||||||
print('chamouuuuuuuuuuu')
|
|
||||||
config = {
|
config = {
|
||||||
'taxa': False
|
'taxa': False
|
||||||
}
|
}
|
||||||
obs = request.GET.get("obs")
|
obs = request.GET.get("obs")
|
||||||
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()
|
||||||
|
Product.subStock(Product.objects.get(id=product_id), 1)
|
||||||
product = Product.objects.get(id=product_id)
|
product = Product.objects.get(id=product_id)
|
||||||
comanda = Comanda.objects.get(id=comanda_id)
|
comanda = Comanda.objects.get(id=comanda_id)
|
||||||
parcial = Payments.objects.filter(comanda=comanda)
|
parcial = Payments.objects.filter(comanda=comanda)
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -106,26 +106,26 @@ WSGI_APPLICATION = 'gestaoRaul.wsgi.application'
|
|||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||||
|
|
||||||
#DATABASES = {
|
|
||||||
# 'default': {
|
|
||||||
# 'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
# 'NAME': BASE_DIR / 'db.sqlite3',
|
|
||||||
# }
|
|
||||||
#}
|
|
||||||
|
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': DB_ENGINE,
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': DB_NAME,
|
'NAME': BASE_DIR / 'db.sqlite3',
|
||||||
'USER': DB_USER,
|
|
||||||
'PASSWORD': DB_PASSWORD,
|
|
||||||
'HOST': DB_HOST,
|
|
||||||
'PORT': DB_PORT,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# DATABASES = {
|
||||||
|
# 'default': {
|
||||||
|
# 'ENGINE': DB_ENGINE,
|
||||||
|
# 'NAME': DB_NAME,
|
||||||
|
# 'USER': DB_USER,
|
||||||
|
# 'PASSWORD': DB_PASSWORD,
|
||||||
|
# 'HOST': DB_HOST,
|
||||||
|
# 'PORT': DB_PORT,
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
|||||||
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)
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
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.shortcuts import render, redirect
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
import json
|
import json
|
||||||
from django.db.models import Q
|
from django.db.models import Q, Count, F
|
||||||
|
|
||||||
|
|
||||||
from categories.models import Categories
|
from categories.models import Categories
|
||||||
|
from comandas.models import ProductComanda
|
||||||
from products.models import Product
|
from products.models import Product
|
||||||
from gestaoRaul.decorators import group_required
|
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})
|
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||||
|
|
||||||
def createJson(request):
|
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(
|
products = Product.objects.filter(active=True).exclude(
|
||||||
category__name__in=['Insumos',
|
category__name__in=['Insumos',
|
||||||
'Adicional',
|
'Adicional',
|
||||||
@@ -76,8 +82,21 @@ def createJson(request):
|
|||||||
'Cigarros',
|
'Cigarros',
|
||||||
'Outros']
|
'Outros']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
products_ordenados = []
|
||||||
|
for produto in produtos_mais_vendidos:
|
||||||
|
for p in products:
|
||||||
|
if p.name == produto['nome']:
|
||||||
|
products_ordenados.append(p)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
product_list = []
|
product_list = []
|
||||||
for product in products:
|
for product in products_ordenados:
|
||||||
product_data = {
|
product_data = {
|
||||||
"id": product.id,
|
"id": product.id,
|
||||||
"name": product.name,
|
"name": product.name,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
async function openModal() {
|
async function modalAddProduct() {
|
||||||
var htmlModal = document.getElementById('addProduct').innerHTML
|
var htmlModal = document.getElementById('addProduct').innerHTML
|
||||||
htmlModal = htmlModal.replace('search-product','search-product-modal')
|
htmlModal = htmlModal.replace('search-product','search-product-modal')
|
||||||
htmlModal = htmlModal.replace('product-list','product-list-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');
|
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
|
// Requisição POST
|
||||||
const response = await fetch(`/comandas/product=${productId}/comanda=${comandaId}/`, {
|
const response = await fetch(`/comandas/product=${productId}/comanda=${comandaId}/`, {
|
||||||
@@ -403,6 +395,7 @@ async function addProductComanda(productId, comandaId, cuisine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.text();
|
const result = await response.text();
|
||||||
|
console.log(response);
|
||||||
|
|
||||||
// Atualiza a lista de produtos
|
// Atualiza a lista de produtos
|
||||||
const listElement = document.getElementById("list-products-comanda");
|
const listElement = document.getElementById("list-products-comanda");
|
||||||
@@ -410,17 +403,11 @@ async function addProductComanda(productId, comandaId, cuisine) {
|
|||||||
listElement.innerHTML = result;
|
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) {
|
} catch (error) {
|
||||||
console.error('Erro:', error);
|
console.error('Erro:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user