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

@@ -716,11 +716,16 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
COALESCE(SUM(planned_quantity), 0) as total_planned,
COALESCE(SUM(actual_quantity), 0) as total_actual,
COUNT(*) as total_batches,
COUNT(CASE WHEN forecast_id IS NOT NULL THEN 1 END) as ai_assisted_batches
COUNT(CASE WHEN is_ai_assisted = true THEN 1 END) as ai_assisted_batches,
COALESCE(SUM(CASE WHEN waste_defect_type = 'burnt' THEN waste_quantity ELSE 0 END), 0) as burnt_waste,
COALESCE(SUM(CASE WHEN waste_defect_type = 'misshapen' THEN waste_quantity ELSE 0 END), 0) as misshapen_waste,
COALESCE(SUM(CASE WHEN waste_defect_type = 'underproofed' THEN waste_quantity ELSE 0 END), 0) as underproofed_waste,
COALESCE(SUM(CASE WHEN waste_defect_type = 'temperature_issues' THEN waste_quantity ELSE 0 END), 0) as temperature_waste,
COALESCE(SUM(CASE WHEN waste_defect_type = 'expired' THEN waste_quantity ELSE 0 END), 0) as expired_waste
FROM production_batches
WHERE tenant_id = :tenant_id
AND created_at BETWEEN :start_date AND :end_date
AND status IN ('COMPLETED', 'QUALITY_CHECK', 'FINISHED')
AND status IN ('COMPLETED', 'QUALITY_CHECK')
""")
result = await self.session.execute(
@@ -739,7 +744,14 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
'total_planned': float(row.total_planned or 0),
'total_actual': float(row.total_actual or 0),
'total_batches': int(row.total_batches or 0),
'ai_assisted_batches': int(row.ai_assisted_batches or 0)
'ai_assisted_batches': int(row.ai_assisted_batches or 0),
'waste_by_defect_type': {
'burnt': float(row.burnt_waste or 0),
'misshapen': float(row.misshapen_waste or 0),
'underproofed': float(row.underproofed_waste or 0),
'temperature_issues': float(row.temperature_waste or 0),
'expired': float(row.expired_waste or 0)
}
}
logger.info(
@@ -783,7 +795,7 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
WHERE tenant_id = :tenant_id
AND created_at BETWEEN first_batch.start_date
AND first_batch.start_date + INTERVAL '90 days'
AND status IN ('COMPLETED', 'QUALITY_CHECK', 'FINISHED')
AND status IN ('COMPLETED', 'QUALITY_CHECK')
)
SELECT
total_waste,
@@ -833,4 +845,4 @@ class ProductionBatchRepository(ProductionBaseRepository, BatchCountProvider):
except Exception as e:
logger.error("Error calculating baseline metrics", error=str(e), tenant_id=str(tenant_id))
raise DatabaseError(f"Failed to calculate baseline metrics: {str(e)}")
raise DatabaseError(f"Failed to calculate baseline metrics: {str(e)}")