fiz um monte de coisa e criei um bug

This commit is contained in:
2025-01-15 11:04:27 -03:00
parent a2fd5d12e3
commit 43d9cd9c5b
20 changed files with 83 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ from django.db.models import Count, F
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from mesas.models import Mesa
from products.models import Product 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
@@ -66,7 +67,12 @@ def removeProductBalcao(request, productComanda_id):
def paymentBalcao(request, comanda_id): def paymentBalcao(request, comanda_id):
typePayment = TypePay.objects.get(id=1) typePayment = TypePay.objects.get(id=1)
consumo = ProductComanda.objects.filter(comanda=comanda_id) consumo = ProductComanda.objects.filter(comanda=comanda_id)
vendasBalcao = Comanda.objects.get(name='VENDAS BALCAO') try:
vendasBalcao = Comanda.objects.get(name='VENDAS BALCAO')
except:
mesa = Mesa.objects.get(id=1)
vendasBalcao = Comanda(name='VENDAS BALCAO', mesa=mesa, user=request.user, status='CLOSED')
vendasBalcao.save()
comanda = Comanda.objects.get(name='VENDA BALCÃO') comanda = Comanda.objects.get(name='VENDA BALCÃO')
total = 0 total = 0
for produto in consumo: for produto in consumo:
@@ -77,3 +83,7 @@ def paymentBalcao(request, comanda_id):
pagamento.save() pagamento.save()
return redirect('viewBalcao') return redirect('viewBalcao')
#"GET /balcao/addProductBalcaoTeclado83/1/1/ HTTP/1.1" 200 747
#"GET /balcao/addProductBalcaoTeclado83/13/1/ HTTP/1.1" 500 133103

View File

@@ -71,8 +71,11 @@
{% for product in products %} {% for product in products %}
{% if forloop.counter0 == 0 %} {% if forloop.counter0 == 0 %}
<article name="productBox" id="productId-{{ product.id }}" <article
onclick="addProductClick({{product.id}} , {{comanda.id}})" style="background-color: #293552;"> name="productBox"
id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})"
style="background-color: #293552;">
<p hidden id="{{forloop.counter0}}">{{product.id}}</p> <p hidden id="{{forloop.counter0}}">{{product.id}}</p>
<p hidden id="comanda{{forloop.counter0}}">{{comanda.id}}</p> <p hidden id="comanda{{forloop.counter0}}">{{comanda.id}}</p>
{{product.name}} <br> {{product.name}} <br>
@@ -82,8 +85,11 @@
{% else %} {% else %}
<article name="productBox" id="productId-{{ product.id }}" <article
onclick="addProductClick({{product.id}} , {{comanda.id}})" style="background-color: #293552;"> name="productBox"
id="productId-{{ product.id }}"
onclick="addProductClick({{product.id}} , {{comanda.id}})"
style="background-color: #293552;">
{{product.name}} <br> {{product.name}} <br>
R$ {{product.price}} R$ {{product.price}}
</article> </article>

View File

@@ -2,13 +2,22 @@ from django.shortcuts import render
from comandas.models import Comanda, ProductComanda from comandas.models import Comanda, ProductComanda
from products.models import Product from products.models import Product
from mesas.models import Mesa
from django.db.models import Count, F from django.db.models import Count, F
from django.contrib.auth.models import User
def viewBalcao(request): def viewBalcao(request):
try:
comanda = Comanda.objects.get(name='VENDA BALCÃO')
except:
user = User.objects.get(id=request.user.id)
mesa = Mesa.objects.get(id=1)
comanda = Comanda(name='VENDA BALCÃO', mesa=mesa, user=user,status='CLOSED')
comanda.save()
comanda = Comanda.objects.get(name='VENDA BALCÃO')
consumo = ProductComanda.objects.filter(comanda=comanda.id) consumo = ProductComanda.objects.filter(comanda=comanda.id)
produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate( produtos_mais_vendidos = list(ProductComanda.objects.values('product').annotate(
quantidade=Count('product'), quantidade=Count('product'),

View File

@@ -0,0 +1,22 @@
# Generated by Django 5.1.4 on 2025-01-15 12:43
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('comandas', '0003_comanda_status_alter_productcomanda_product'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddField(
model_name='comanda',
name='user',
field=models.ForeignKey(blank=True, default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]

View File

@@ -1,4 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User
from clients.models import Client from clients.models import Client
from products.models import Product from products.models import Product
@@ -8,6 +10,7 @@ from typePay.models import TypePay
class Comanda(models.Model): class Comanda(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
mesa = models.ForeignKey(Mesa, on_delete=models.CASCADE) mesa = models.ForeignKey(Mesa, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=True)
type_pay = models.ForeignKey(TypePay, on_delete=models.SET_NULL, null=True) type_pay = models.ForeignKey(TypePay, on_delete=models.SET_NULL, null=True)
dt_open = models.DateTimeField(auto_now_add=True) dt_open = models.DateTimeField(auto_now_add=True)
dt_close = models.DateTimeField(null=True, blank=True) dt_close = models.DateTimeField(null=True, blank=True)

View File

@@ -40,7 +40,7 @@ def createComanda(request):
name = request.POST.get('name-comanda') name = request.POST.get('name-comanda')
mesa_id = int(request.POST.get('select-mesa')[0]) mesa_id = int(request.POST.get('select-mesa')[0])
mesa = Mesa.objects.get(id=mesa_id) mesa = Mesa.objects.get(id=mesa_id)
comanda = Comanda(name=name, mesa=mesa) comanda = Comanda(name=name, mesa=mesa, user=request.user)
comanda.save() comanda.save()
return redirect('comandas') return redirect('comandas')

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -14,15 +14,19 @@ from gestaoRaul.decorators import group_required
@group_required(groupName='Gerente') @group_required(groupName='Gerente')
def home(request): def home(request):
total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total'] try:
qdt_pagamentos = Payments.objects.aggregate(total=Count('value'))['total'] total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total']
pagamentos = Payments.objects.all() qdt_pagamentos = Payments.objects.aggregate(total=Count('value'))['total']
ticekMedio = total_pagamentos / qdt_pagamentos pagamentos = Payments.objects.all()
ticekMedio = total_pagamentos / qdt_pagamentos
produtos_mais_vendidos = ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade')[:5]
return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos, 'ticekMedio': ticekMedio, })
except:
return render(request, 'home.html')
produtos_mais_vendidos = ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade')[:5]
return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos, 'ticekMedio': ticekMedio, })
@group_required(groupName='Gerente') @group_required(groupName='Gerente')
def chartCuisine(request): def chartCuisine(request):

View File

@@ -48,6 +48,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -72,6 +73,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'finished' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'finished' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -95,6 +97,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'delivered' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'delivered' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -118,6 +121,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<!-- <button>Preparar</button> --> <!-- <button>Preparar</button> -->
</div> </div>

View File

@@ -2,7 +2,8 @@
{% for product in products %} {% for product in products %}
{% if forloop.counter0 == 0 %} {% if forloop.counter0 == 0 %}
<input hidden type="text" id="idComanda0" value="{{comanda_id}}">
<article <article
name="productBox" name="productBox"
@@ -11,7 +12,7 @@
onclick="addProductClick({{product.id}} , {{comanda_id}})" onclick="addProductClick({{product.id}} , {{comanda_id}})"
> >
<p hidden id="{{forloop.counter0}}" >{{product.id}}</p> <p hidden id="{{forloop.counter0}}" >{{product.id}}</p>
<p hidden id="comanda{{forloop.counter0}}" >{{comanda_id}}</p> <p hidden id="comanda{{forloop.counter0}}" >{{comanda.id}}</p>
{{product.name}} <br> <p id="{{product.id}}"></p> {{product.name}} <br> <p id="{{product.id}}"></p>
R$ {{product.price}} R$ {{product.price}}
</article > </article >
@@ -22,7 +23,7 @@
name="productBox" name="productBox"
id="productId-{{ product.id }}" id="productId-{{ product.id }}"
style="background-color: #293552;" style="background-color: #293552;"
onclick="addProductClick({{product.id}} , {{comanda_id}})" onclick="addProductClick({{product.id}} , {{comanda.id}})"
> >
{{product.name}} <br> {{product.name}} <br>
R$ {{product.price}} R$ {{product.price}}

View File

@@ -21,6 +21,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -45,6 +46,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'finished' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'finished' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -68,6 +70,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<button <button
hx-get="{% url 'delivered' order.id %} " hx-trigger="click" hx-target="#list-orders" hx-get="{% url 'delivered' order.id %} " hx-trigger="click" hx-target="#list-orders"
@@ -91,6 +94,7 @@
<h4>{{order.id_product.name}}</h4> <h4>{{order.id_product.name}}</h4>
<h4>{{order.obs}} </h4> <h4>{{order.obs}} </h4>
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4> <h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4> <h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
<!-- <button>Preparar</button> --> <!-- <button>Preparar</button> -->
</div> </div>

View File

@@ -150,8 +150,9 @@ 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");
var comanda_id = document.getElementById("idComanda0").value;
if(search_product.length == 0 ){search_product ='*';} if(search_product.length == 0 ){search_product ='*';}
fetch(`/balcao/listProductBalcao/13/${search_product}`, { fetch(`/balcao/listProductBalcao/${comanda_id}/${search_product}`, {
method: 'GET',} method: 'GET',}
).then(function(response) { ).then(function(response) {
return response.text(); return response.text();