Imporve the i18 and frontend UI pages

This commit is contained in:
Urtzi Alfaro
2025-09-22 16:10:08 +02:00
parent ee36c45d25
commit 8d54202e91
32 changed files with 875 additions and 434 deletions

View File

@@ -8,8 +8,11 @@ Procurement API Endpoints - RESTful APIs for procurement planning
import uuid
from datetime import date
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, Query, status
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
from sqlalchemy.ext.asyncio import AsyncSession
import structlog
logger = structlog.get_logger()
from app.core.database import get_db
from app.core.config import settings
@@ -131,12 +134,12 @@ async def get_procurement_plan_by_date(
@monitor_performance("list_procurement_plans")
async def list_procurement_plans(
tenant_id: uuid.UUID,
status: Optional[str] = Query(None, description="Filter by plan status"),
plan_status: Optional[str] = Query(None, description="Filter by plan status"),
start_date: Optional[date] = Query(None, description="Start date filter (YYYY-MM-DD)"),
end_date: Optional[date] = Query(None, description="End date filter (YYYY-MM-DD)"),
limit: int = Query(50, ge=1, le=100, description="Number of plans to return"),
offset: int = Query(0, ge=0, description="Number of plans to skip"),
tenant_access: TenantAccess = Depends(get_current_tenant),
# tenant_access: TenantAccess = Depends(get_current_tenant),
procurement_service: ProcurementService = Depends(get_procurement_service)
):
"""
@@ -147,8 +150,8 @@ async def list_procurement_plans(
try:
# Get plans from repository directly for listing
plans = await procurement_service.plan_repo.list_plans(
tenant_access.tenant_id,
status=status,
tenant_id,
status=plan_status,
start_date=start_date,
end_date=end_date,
limit=limit,
@@ -156,7 +159,14 @@ async def list_procurement_plans(
)
# Convert to response models
plan_responses = [ProcurementPlanResponse.model_validate(plan) for plan in plans]
plan_responses = []
for plan in plans:
try:
plan_response = ProcurementPlanResponse.model_validate(plan)
plan_responses.append(plan_response)
except Exception as validation_error:
logger.error(f"Error validating plan {plan.id}: {validation_error}")
raise
# For simplicity, we'll use the returned count as total
# In a production system, you'd want a separate count query
@@ -404,24 +414,33 @@ async def get_critical_requirements(
@monitor_performance("trigger_daily_scheduler")
async def trigger_daily_scheduler(
tenant_id: uuid.UUID,
tenant_access: TenantAccess = Depends(get_current_tenant),
procurement_service: ProcurementService = Depends(get_procurement_service)
request: Request
):
"""
Manually trigger the daily scheduler for the current tenant
This endpoint is primarily for testing and maintenance purposes.
Note: Authentication temporarily disabled for development testing.
"""
try:
# Process daily plan for current tenant only
await procurement_service._process_daily_plan_for_tenant(tenant_access.tenant_id)
return {
"success": True,
"message": "Daily scheduler executed successfully",
"tenant_id": str(tenant_access.tenant_id)
}
# Get the scheduler service from app state and call process_tenant_procurement
if hasattr(request.app.state, 'scheduler_service'):
scheduler_service = request.app.state.scheduler_service
await scheduler_service.process_tenant_procurement(tenant_id)
return {
"success": True,
"message": "Daily scheduler executed successfully for tenant",
"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:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -429,6 +448,7 @@ async def trigger_daily_scheduler(
)
@router.get("/procurement/health")
async def procurement_health_check():
"""