Improve the frontend and fix TODOs

This commit is contained in:
Urtzi Alfaro
2025-10-24 13:05:04 +02:00
parent 07c33fa578
commit 61376b7a9f
100 changed files with 8284 additions and 3419 deletions

View File

@@ -4,7 +4,7 @@ Production Operations API - Business operations for production management
Includes: batch start/complete, schedule finalize/optimize, capacity management, transformations, stats
"""
from fastapi import APIRouter, Depends, HTTPException, Path, Query
from fastapi import APIRouter, Depends, HTTPException, Path, Query, Request, status
from typing import Optional
from datetime import date, datetime, timedelta
from uuid import UUID
@@ -12,6 +12,7 @@ import structlog
from shared.auth.decorators import get_current_user_dep
from shared.routing import RouteBuilder
from shared.monitoring.decorators import monitor_performance
from app.services.production_service import ProductionService
from app.schemas.production import (
ProductionBatchResponse,
@@ -394,3 +395,50 @@ async def transform_par_baked_products(
logger.error("Error transforming products",
error=str(e), tenant_id=str(tenant_id))
raise HTTPException(status_code=500, detail="Failed to transform products")
# ===== SCHEDULER OPERATIONS =====
@router.post(
route_builder.build_operations_route("scheduler/trigger")
)
@monitor_performance("trigger_production_scheduler")
async def trigger_production_scheduler(
tenant_id: UUID = Path(...),
request: Request = None
):
"""
Manually trigger the production scheduler for the current tenant
This endpoint is primarily for testing and development purposes.
Triggers the production schedule generation process manually.
"""
try:
# Get the scheduler service from app state
if hasattr(request.app.state, 'scheduler_service'):
scheduler_service = request.app.state.scheduler_service
await scheduler_service.test_production_schedule_generation()
logger.info("Production scheduler triggered manually",
tenant_id=str(tenant_id))
return {
"success": True,
"message": "Production scheduler executed successfully",
"tenant_id": str(tenant_id)
}
else:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="Scheduler service is not available"
)
except HTTPException:
raise
except Exception as e:
logger.error("Error triggering production scheduler",
error=str(e), tenant_id=str(tenant_id))
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Error triggering production scheduler: {str(e)}"
)