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

@@ -159,9 +159,37 @@ async def get_supplier_performance_metrics(
):
"""Get performance metrics for a supplier"""
try:
# TODO: Implement get_supplier_performance_metrics in service
# For now, return empty list
metrics = []
from app.models.performance import SupplierPerformanceMetric
from sqlalchemy import select, and_, desc
# Build query for performance metrics
query = select(SupplierPerformanceMetric).where(
and_(
SupplierPerformanceMetric.supplier_id == supplier_id,
SupplierPerformanceMetric.tenant_id == tenant_id
)
)
# Apply filters
if metric_type:
query = query.where(SupplierPerformanceMetric.metric_type == metric_type)
if date_from:
query = query.where(SupplierPerformanceMetric.calculated_at >= date_from)
if date_to:
query = query.where(SupplierPerformanceMetric.calculated_at <= date_to)
# Order by most recent and apply limit
query = query.order_by(desc(SupplierPerformanceMetric.calculated_at)).limit(limit)
result = await db.execute(query)
metrics = result.scalars().all()
logger.info("Retrieved performance metrics",
tenant_id=str(tenant_id),
supplier_id=str(supplier_id),
count=len(metrics))
return metrics
@@ -227,9 +255,39 @@ async def get_supplier_alerts(
):
"""Get supplier alerts with filtering"""
try:
# TODO: Implement get_supplier_alerts in service
# For now, return empty list
alerts = []
from app.models.performance import SupplierAlert
from sqlalchemy import select, and_, desc
# Build query for alerts
query = select(SupplierAlert).where(
SupplierAlert.tenant_id == tenant_id
)
# Apply filters
if supplier_id:
query = query.where(SupplierAlert.supplier_id == supplier_id)
if alert_type:
query = query.where(SupplierAlert.alert_type == alert_type)
if severity:
query = query.where(SupplierAlert.severity == severity)
if date_from:
query = query.where(SupplierAlert.created_at >= date_from)
if date_to:
query = query.where(SupplierAlert.created_at <= date_to)
# Order by most recent and apply limit
query = query.order_by(desc(SupplierAlert.created_at)).limit(limit)
result = await db.execute(query)
alerts = result.scalars().all()
logger.info("Retrieved supplier alerts",
tenant_id=str(tenant_id),
count=len(alerts))
return alerts