mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
chore: Delete numerous application modules, templates, static assets, documentation, and build files.
This commit is contained in:
0
orders/__init__.py
Normal file
0
orders/__init__.py
Normal file
6
orders/admin.py
Normal file
6
orders/admin.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from orders.models import Order
|
||||
|
||||
|
||||
admin.site.register(Order)
|
||||
47
orders/api_views.py
Normal file
47
orders/api_views.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from rest_framework import viewsets, permissions, status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from .models import Order
|
||||
from .serializers import OrderSerializer
|
||||
from django.utils import timezone
|
||||
|
||||
class OrderViewSet(viewsets.ModelViewSet):
|
||||
queryset = Order.objects.all()
|
||||
serializer_field = OrderSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
# Filtrar pedidos das últimas 15 horas como na view original
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
return Order.objects.filter(queue__gte=fifteen_hours_ago).order_by('-queue')
|
||||
|
||||
def get_serializer_class(self):
|
||||
return OrderSerializer
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def preparing(self, request, pk=None):
|
||||
order = self.get_object()
|
||||
order.preparing = timezone.now()
|
||||
order.save()
|
||||
return Response(OrderSerializer(order).data)
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def finish(self, request, pk=None):
|
||||
order = self.get_object()
|
||||
order.finished = timezone.now()
|
||||
order.save()
|
||||
return Response(OrderSerializer(order).data)
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def deliver(self, request, pk=None):
|
||||
order = self.get_object()
|
||||
order.delivered = timezone.now()
|
||||
order.save()
|
||||
return Response(OrderSerializer(order).data)
|
||||
|
||||
@action(detail=True, methods=['post'])
|
||||
def cancel(self, request, pk=None):
|
||||
order = self.get_object()
|
||||
order.canceled = timezone.now()
|
||||
order.save()
|
||||
return Response(OrderSerializer(order).data)
|
||||
6
orders/apps.py
Normal file
6
orders/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class OrdersConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'orders'
|
||||
31
orders/migrations/0001_initial.py
Normal file
31
orders/migrations/0001_initial.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-10 16:28
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('comandas', '0003_comanda_status_alter_productcomanda_product'),
|
||||
('products', '0003_product_cuisine'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Order',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('obs', models.TextField(blank=True, null=True)),
|
||||
('queue', models.DateTimeField(auto_now_add=True)),
|
||||
('preparing', models.DateTimeField(blank=True, null=True)),
|
||||
('finished', models.DateTimeField(blank=True, null=True)),
|
||||
('delivered', models.DateTimeField(blank=True, null=True)),
|
||||
('canceled', models.DateTimeField(blank=True, null=True)),
|
||||
('id_comanda', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comandas.comanda')),
|
||||
('id_product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='products.product')),
|
||||
],
|
||||
),
|
||||
]
|
||||
20
orders/migrations/0002_order_productcomanda.py
Normal file
20
orders/migrations/0002_order_productcomanda.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-10 19:24
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('comandas', '0003_comanda_status_alter_productcomanda_product'),
|
||||
('orders', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='productComanda',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='comandas.productcomanda'),
|
||||
),
|
||||
]
|
||||
0
orders/migrations/__init__.py
Normal file
0
orders/migrations/__init__.py
Normal file
31
orders/models.py
Normal file
31
orders/models.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.db import models
|
||||
from django.utils.formats import date_format
|
||||
from datetime import timedelta
|
||||
|
||||
from products.models import Product
|
||||
from comandas.models import Comanda, ProductComanda
|
||||
|
||||
|
||||
class Order(models.Model):
|
||||
productComanda = models.ForeignKey(ProductComanda, on_delete=models.SET_NULL, null=True)
|
||||
id_product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
||||
id_comanda = models.ForeignKey(Comanda, on_delete=models.CASCADE)
|
||||
obs = models.TextField(blank=True, null=True)
|
||||
queue = models.DateTimeField(auto_now_add=True)
|
||||
preparing = models.DateTimeField(null=True, blank=True)
|
||||
finished = models.DateTimeField(null=True, blank=True)
|
||||
delivered = models.DateTimeField(null=True, blank=True)
|
||||
canceled = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
status = 'Em espera'
|
||||
datetime = self.queue - timedelta(hours=3)
|
||||
|
||||
if self.preparing:
|
||||
status = 'Preparando'
|
||||
if self.finished:
|
||||
status = 'Pronto'
|
||||
if self.delivered:
|
||||
status = 'Entregue'
|
||||
|
||||
return f"{self.id_product}| {self.obs}|{status}|{self.id_comanda.name}|{self.id_comanda.mesa.name}|{date_format(datetime, 'd/m/Y H:i')}"
|
||||
31
orders/serializers.py
Normal file
31
orders/serializers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Order
|
||||
|
||||
class OrderSerializer(serializers.ModelSerializer):
|
||||
status = serializers.SerializerMethodField()
|
||||
product_name = serializers.ReadOnlyField(source='id_product.name')
|
||||
comanda_name = serializers.ReadOnlyField(source='id_comanda.name')
|
||||
mesa_name = serializers.ReadOnlyField(source='id_comanda.mesa.name')
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = [
|
||||
'id', 'id_product', 'product_name', 'id_comanda', 'comanda_name',
|
||||
'mesa_name', 'obs', 'queue', 'preparing', 'finished',
|
||||
'delivered', 'canceled', 'status'
|
||||
]
|
||||
extra_kwargs = {
|
||||
'queue': {'read_only': True},
|
||||
'status': {'read_only': True},
|
||||
}
|
||||
|
||||
def get_status(self, obj):
|
||||
if obj.delivered:
|
||||
return 'Entregue'
|
||||
if obj.finished:
|
||||
return 'Pronto'
|
||||
if obj.preparing:
|
||||
return 'Preparando'
|
||||
if obj.canceled:
|
||||
return 'Cancelado'
|
||||
return 'Em espera'
|
||||
148
orders/templates/orders.html
Normal file
148
orders/templates/orders.html
Normal file
@@ -0,0 +1,148 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load custom_filter_tag %}
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
{% block 'head' %}
|
||||
<link rel="stylesheet" href="{% static 'orders/css/orders.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block 'title' %}
|
||||
Pedidos Cozinha
|
||||
{% endblock %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block 'body' %}
|
||||
<div class="container">
|
||||
<h1 id="title">Pedidos cozinha</h1>
|
||||
<div class="kanban-board">
|
||||
{% csrf_token %}
|
||||
<div class="column">
|
||||
<h2>FILA</h2>
|
||||
<div id="fila" class="cards-container">
|
||||
{% for order in orders %}
|
||||
{% if order.preparing == None and order.productComanda != Null %}
|
||||
<div class="m-card" id="m-card-{{order.id}}"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </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>
|
||||
{% if user|groupUser:"Cozinha" %}
|
||||
|
||||
<form method="path" action="{% url 'preparing' order.id %}">
|
||||
|
||||
<button class="btn-primary" type="submit">Preparar</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<h2>PREPARANDO</h2>
|
||||
<div class="cards-container">
|
||||
{% for order in orders %}
|
||||
{% if order.finished == None and order.preparing != None %}
|
||||
<div class="m-card" id="m-card-{{order.id}}"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </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>
|
||||
{% if user|groupUser:"Cozinha" %}
|
||||
<form method="path" action="{% url 'finished' order.id %}">
|
||||
<button class="btn-primary" type="submit">Finalizar</button>
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<h2>PRONTO</h2>
|
||||
<div class="cards-container">
|
||||
{% for order in orders %}
|
||||
{% if order.delivered == None and order.finished != None %}
|
||||
<div class="m-card" id="m-card-{{order.id}}"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </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>
|
||||
{% if user|groupUser:"Garçom" %}
|
||||
<form method="path" action="{% url 'delivered' order.id %}">
|
||||
<button class="btn-primary" type="submit">Entregar</button>
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="column"
|
||||
{% if user|groupUser:"Gerente" %}
|
||||
style="display:block"
|
||||
{% else %}
|
||||
style="display:none"
|
||||
{% endif %}
|
||||
|
||||
>
|
||||
<h2>ENTREGUE</h2>
|
||||
<div class="cards-container">
|
||||
{% for order in orders %}
|
||||
{% if order.delivered != None %}
|
||||
<div class="m-card" id="m-card-{{order.id}}"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </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>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="{% static 'orders/js/orders.js' %}"></script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
3
orders/tests.py
Normal file
3
orders/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
13
orders/urls.py
Normal file
13
orders/urls.py
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.viewsOrders, name='pedidos'),
|
||||
path('preparing/<int:order_id>/', views.preparing, name='preparing'),
|
||||
path('finished/<int:order_id>/', views.finished, name='finished'),
|
||||
path('delivered/<int:order_id>/', views.delivered, name='delivered'),
|
||||
path('notificacao/', views.notificacao, name='notificacao'),
|
||||
|
||||
|
||||
]
|
||||
99
orders/views.py
Normal file
99
orders/views.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# from datetime import timezone
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
import asyncio
|
||||
import websockets
|
||||
|
||||
|
||||
from orders.models import Order
|
||||
from django.db.models import Q
|
||||
from gestaoRaul.decorators import group_required
|
||||
|
||||
|
||||
async def enviar_mensagem(message):
|
||||
uri = "ws://192.168.1.150:8765"
|
||||
async with websockets.connect(uri) as websocket:
|
||||
await websocket.send(message)
|
||||
print(f"> Enviado: {message}")
|
||||
|
||||
resposta = await websocket.recv()
|
||||
print(f"< Recebido: {resposta}")
|
||||
|
||||
|
||||
|
||||
|
||||
def viewsOrders(request):
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
return render(request, 'orders.html',{'orders': orders})
|
||||
|
||||
@group_required(groupName='Cozinha')
|
||||
def preparing(request, order_id):
|
||||
order = Order.objects.get(id=order_id)
|
||||
order.preparing = timezone.now()
|
||||
order.save()
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
return redirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
|
||||
@group_required(groupName='Cozinha')
|
||||
def finished(request, order_id):
|
||||
order = Order.objects.get(id=order_id)
|
||||
order.finished = timezone.now()
|
||||
order.save()
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
# asyncio.run(enviar_mensagem())
|
||||
return redirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
def delivered(request, order_id):
|
||||
order = Order.objects.get(id=order_id)
|
||||
order.delivered = timezone.now()
|
||||
order.save()
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
return redirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
|
||||
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)
|
||||
|
||||
grupoCozinha = request.user.groups.filter(name='Cozinha').exists()
|
||||
grupoGerente = request.user.groups.filter(name='Gerente').exists()
|
||||
|
||||
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),
|
||||
'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name,
|
||||
'corpo': ordersFila[len(ordersFila)-1].id_product.name,
|
||||
})
|
||||
else:
|
||||
return JsonResponse({
|
||||
'notificacao': 'false',
|
||||
'fila': len(ordersFila),
|
||||
})
|
||||
else:
|
||||
return JsonResponse({
|
||||
'notificacao': 'true',
|
||||
'fila': len(ordersFila),
|
||||
'titulo': 'Pedido para: '+ ordersFila[len(ordersFila)-1].id_comanda.name,
|
||||
'corpo': ordersFila[len(ordersFila)-1].id_product.name,
|
||||
})
|
||||
|
||||
|
||||
else:
|
||||
return JsonResponse({
|
||||
'notificacao': 'false',
|
||||
'fila': len(ordersFila),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user