grafico cozinha dinamico

This commit is contained in:
2025-01-13 10:34:16 -03:00
parent 7b01316834
commit c7687f7b9a
7 changed files with 88 additions and 7 deletions

View File

@@ -1,9 +1,11 @@
from django.shortcuts import render
from django.db.models import Sum
from django.db.models import Count, F
from django.http import JsonResponse
from comandas.models import ProductComanda
from products.models import Product
from orders.models import Order
from payments.models import Payments
def home(request):
@@ -15,5 +17,34 @@ def home(request):
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})
def chartCuisine(request):
print('entrooooooouuuuu')
tFila = []
tPreparando = []
tFinalizado = []
orders = Order.objects.filter(delivered__isnull=False)
for order in orders:
tFila.append((order.preparing - order.queue).total_seconds())
tPreparando.append((order.finished - order.preparing).total_seconds())
tFinalizado.append((order.delivered - order.finished).total_seconds())
mediaFila = int((sum(tFila) / len(tFila))/60)
mediaPreparando = int((sum(tPreparando) / len(tPreparando))/60)
mediaFinalizado = int((sum(tFinalizado) / len(tFinalizado))/60)
# orders = Order.objects.filter(
# created_at__gte='a',
# created_at__lte='b',
# delivered__isnull=False
# )
return JsonResponse({
'mediaFila': mediaFila,
'mediaPreparando': mediaPreparando,
'mediaFinalizado': mediaFinalizado,
})