Initial commit
This commit is contained in:
47
app/api/routes/kanban.py
Normal file
47
app/api/routes/kanban.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from prisma import Prisma
|
||||
from typing import Dict, List
|
||||
from app.api.dependencies import get_prisma
|
||||
from app.models.pedido_cliente import PedidoClienteResponse
|
||||
|
||||
router = APIRouter(prefix="/kanban", tags=["kanban"])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def obtener_kanban(
|
||||
db: Prisma = Depends(get_prisma)
|
||||
) -> Dict[str, List[Dict]]:
|
||||
"""Obtener datos del Kanban agrupados por estado"""
|
||||
pedidos = await db.pedidocliente.find_many(
|
||||
include={
|
||||
"cliente": True,
|
||||
"referencias": True
|
||||
},
|
||||
order_by={"fechaPedido": "desc"}
|
||||
)
|
||||
|
||||
# Agrupar por estado
|
||||
kanban_data = {
|
||||
"pendiente_revision": [],
|
||||
"en_revision": [],
|
||||
"pendiente_materiales": [],
|
||||
"completado": [],
|
||||
}
|
||||
|
||||
for pedido in pedidos:
|
||||
pedido_dict = pedido.dict()
|
||||
# Calcular es_urgente
|
||||
from datetime import datetime, timedelta
|
||||
if pedido.fechaCita:
|
||||
ahora = datetime.now(pedido.fechaCita.tzinfo) if pedido.fechaCita.tzinfo else datetime.now()
|
||||
tiempo_restante = pedido.fechaCita - ahora
|
||||
pedido_dict["es_urgente"] = 0 < tiempo_restante.total_seconds() < 12 * 3600
|
||||
else:
|
||||
pedido_dict["es_urgente"] = False
|
||||
|
||||
estado = pedido.estado
|
||||
if estado in kanban_data:
|
||||
kanban_data[estado].append(pedido_dict)
|
||||
|
||||
return kanban_data
|
||||
|
||||
Reference in New Issue
Block a user