diff --git a/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc index 4c1d3ee..5962582 100644 Binary files a/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc and b/gestaoRaul/comandas/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc b/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc index 207b324..48f954d 100644 Binary files a/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc and b/gestaoRaul/comandas/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/comandas/urls.py b/gestaoRaul/comandas/urls.py index 6a05852..4b947d2 100644 --- a/gestaoRaul/comandas/urls.py +++ b/gestaoRaul/comandas/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ path('createComanda/', views.createComanda, name='createComanda'), path('editComanda/', views.editComanda, name='editComanda'), path('addContaCliente/', views.addContaCliente, name='addContaCliente'), + path('notificacao/', views.notificacao, name='notificacao'), diff --git a/gestaoRaul/comandas/views.py b/gestaoRaul/comandas/views.py index 74a2304..5963bf9 100644 --- a/gestaoRaul/comandas/views.py +++ b/gestaoRaul/comandas/views.py @@ -1,9 +1,13 @@ from decimal import Decimal +from django.utils import timezone + +from django.http import JsonResponse from django.shortcuts import render, redirect from django.db.models import Count, F from comandas.models import Comanda, ProductComanda from clients.models import Client +from orders.models import Order from products.models import Product from mesas.models import Mesa from gestaoRaul.decorators import group_required @@ -76,3 +80,39 @@ def addContaCliente(request): comanda.save() return redirect('comandas') +def notificacao(request): + fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15) + ordersPronto = Order.objects.filter(queue__gte=fifteen_hours_ago, finished__isnull=False) + + grupoGarcom = request.user.groups.filter(name='Garçom').exists() + grupoGerente = request.user.groups.filter(name='Gerente').exists() + + if grupoGarcom == True and grupoGerente == False: + if 'pronto' in request.COOKIES: + cookiesPronto = int(request.COOKIES['pronto']) + if len(ordersPronto) > cookiesPronto: + return JsonResponse({ + 'notificacao': 'true', + 'pronto':len(ordersPronto), + 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, + 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + }) + else: + return JsonResponse({ + 'notificacao': 'false', + 'pronto': len(ordersPronto), + }) + else: + return JsonResponse({ + 'notificacao': 'true', + 'pronto':len(ordersPronto), + 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, + 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + }) + + + else: + return JsonResponse({ + 'notificacao': 'false', + 'pronto':len(ordersPronto), + }) diff --git a/gestaoRaul/db.sqlite3 b/gestaoRaul/db.sqlite3 index 7324541..d8c3bbf 100644 Binary files a/gestaoRaul/db.sqlite3 and b/gestaoRaul/db.sqlite3 differ diff --git a/gestaoRaul/orders/__pycache__/urls.cpython-310.pyc b/gestaoRaul/orders/__pycache__/urls.cpython-310.pyc index 46143da..f6b2e6c 100644 Binary files a/gestaoRaul/orders/__pycache__/urls.cpython-310.pyc and b/gestaoRaul/orders/__pycache__/urls.cpython-310.pyc differ diff --git a/gestaoRaul/orders/__pycache__/views.cpython-310.pyc b/gestaoRaul/orders/__pycache__/views.cpython-310.pyc index 2b3471b..8332794 100644 Binary files a/gestaoRaul/orders/__pycache__/views.cpython-310.pyc and b/gestaoRaul/orders/__pycache__/views.cpython-310.pyc differ diff --git a/gestaoRaul/orders/templates/orders.html b/gestaoRaul/orders/templates/orders.html index 00df152..56274f5 100644 --- a/gestaoRaul/orders/templates/orders.html +++ b/gestaoRaul/orders/templates/orders.html @@ -130,8 +130,8 @@ -
- +
+


Carregando...

diff --git a/gestaoRaul/orders/views.py b/gestaoRaul/orders/views.py index 01a5c9a..dea1766 100644 --- a/gestaoRaul/orders/views.py +++ b/gestaoRaul/orders/views.py @@ -47,21 +47,17 @@ def notificacao(request): fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15) ordersFila = Order.objects.filter(queue__gte=fifteen_hours_ago) ordersPronto = Order.objects.filter(queue__gte=fifteen_hours_ago, finished__isnull=False) - print(len(ordersFila)) - print(len(ordersPronto)) grupoCozinha = request.user.groups.filter(name='Cozinha').exists() - grupoGarcom = request.user.groups.filter(name='Garçom').exists() grupoGerente = request.user.groups.filter(name='Gerente').exists() - if grupoCozinha == True: + if grupoCozinha == True and grupoGerente == False: if 'fila' in request.COOKIES: cookiesFila = int(request.COOKIES['fila']) if len(ordersFila) > cookiesFila: return JsonResponse({ 'notificacao': 'true', 'fila': len(ordersFila), - 'pronto':len(ordersPronto), 'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name, 'corpo': ordersFila[len(ordersFila)-1].id_product.name, }) @@ -69,51 +65,20 @@ def notificacao(request): return JsonResponse({ 'notificacao': 'false', 'fila': len(ordersFila), - 'pronto':len(ordersPronto), }) else: return JsonResponse({ 'notificacao': 'true', 'fila': len(ordersFila), - 'pronto':len(ordersPronto), 'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name, 'corpo': ordersFila[len(ordersFila)-1].id_product.name, }) - elif grupoGarcom == True and grupoGerente == False: - - if 'pronto' in request.COOKIES: - cookiesPronto = int(request.COOKIES['pronto']) - if len(ordersPronto) > cookiesPronto: - return JsonResponse({ - 'notificacao': 'true', - 'fila': len(ordersPronto), - 'pronto':len(ordersPronto), - 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, - 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, - }) - else: - return JsonResponse({ - 'notificacao': 'false', - 'fila': len(ordersPronto), - }) - else: - return JsonResponse({ - 'notificacao': 'false', - 'fila': len(ordersPronto), - 'pronto':len(ordersPronto), - 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, - 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, - }) - - + else: return JsonResponse({ 'notificacao': 'false', - 'fila': len(ordersPronto), - 'pronto':len(ordersPronto), - 'titulo': ordersPronto[len(ordersPronto)-1].id_comanda.name, - 'corpo': ordersPronto[len(ordersPronto)-1].id_product.name, + 'fila': len(ordersFila), }) \ No newline at end of file diff --git a/gestaoRaul/templates/static/comandas/js/comandas.js b/gestaoRaul/templates/static/comandas/js/comandas.js index 57a19dc..570b78f 100644 --- a/gestaoRaul/templates/static/comandas/js/comandas.js +++ b/gestaoRaul/templates/static/comandas/js/comandas.js @@ -50,7 +50,7 @@ function mostrarNotificacao(titulo,corpo,grupo) { function notificacao(){ - var resposta = fetch(`/pedidos/notificacao/`, {method: 'GET', + var resposta = fetch(`/comandas/notificacao/`, {method: 'GET', headers: {'Content-Type': 'application/json', },}) .then(response => response.json()) @@ -60,17 +60,14 @@ function notificacao(){ document.cookie = `pronto=${data['pronto']}`; // navigator.vibrate(200); // navigator.vibrate([200, 100, 200]); - mostrarNotificacao(data['titulo'], data['corpo'],'Cozinha') + mostrarNotificacao(data['titulo'], data['corpo'],'Garçom') console.log(data['notificacao']) }else{ document.cookie = `pronto=${data['pronto']}`; console.log('falso') console.log(data['notificacao']) - console.log('notificação foi false') } - // var produtos_mais_vendidos = data.produtos_mais_vendidos - }) .catch(error => { alert('Erro verificar notificação:', error)