Improve the production frontend

This commit is contained in:
Urtzi Alfaro
2025-09-21 07:45:19 +02:00
parent 5e941f5f03
commit 13ca3e90b4
21 changed files with 1416 additions and 1357 deletions

View File

@@ -49,14 +49,14 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
max_instances=1
)
# Equipment monitoring - every 3 minutes (alerts)
self.scheduler.add_job(
self.check_equipment_status,
CronTrigger(minute='*/3'),
id='equipment_check',
misfire_grace_time=30,
max_instances=1
)
# Equipment monitoring - disabled (equipment tables not available in production database)
# self.scheduler.add_job(
# self.check_equipment_status,
# CronTrigger(minute='*/3'),
# id='equipment_check',
# misfire_grace_time=30,
# max_instances=1
# )
# Efficiency recommendations - every 30 minutes (recommendations)
self.scheduler.add_job(
@@ -127,7 +127,7 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
FROM production_batches pb
WHERE pb.planned_start_time >= CURRENT_DATE
AND pb.planned_start_time <= CURRENT_DATE + INTERVAL '3 days'
AND pb.status IN ('planned', 'pending', 'in_progress')
AND pb.status IN ('PLANNED', 'PENDING', 'IN_PROGRESS')
GROUP BY pb.tenant_id, DATE(pb.planned_start_time)
HAVING COUNT(*) > 10 -- Alert if more than 10 batches per day
ORDER BY total_planned DESC
@@ -226,15 +226,15 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
COALESCE(pb.priority::text, 'medium') as priority_level,
1 as affected_orders -- Default to 1 since we can't count orders
FROM production_batches pb
WHERE pb.status IN ('in_progress', 'delayed')
WHERE pb.status IN ('IN_PROGRESS', 'DELAYED')
AND (
(pb.planned_end_time < NOW() AND pb.status = 'in_progress')
OR pb.status = 'delayed'
(pb.planned_end_time < NOW() AND pb.status = 'IN_PROGRESS')
OR pb.status = 'DELAYED'
)
AND pb.planned_end_time > NOW() - INTERVAL '24 hours'
ORDER BY
CASE COALESCE(pb.priority::text, 'medium')
WHEN 'urgent' THEN 1 WHEN 'high' THEN 2 ELSE 3
CASE COALESCE(pb.priority::text, 'MEDIUM')
WHEN 'URGENT' THEN 1 WHEN 'HIGH' THEN 2 ELSE 3
END,
delay_minutes DESC
"""
@@ -481,7 +481,7 @@ class ProductionAlertService(BaseAlertService, AlertServiceMixin):
AVG(pb.yield_percentage) as avg_yield,
EXTRACT(hour FROM pb.actual_start_time) as start_hour
FROM production_batches pb
WHERE pb.status = 'completed'
WHERE pb.status = 'COMPLETED'
AND pb.actual_completion_time > CURRENT_DATE - INTERVAL '30 days'
AND pb.tenant_id = $1
GROUP BY pb.tenant_id, pb.product_name, EXTRACT(hour FROM pb.actual_start_time)

View File

@@ -78,7 +78,6 @@ class ProductionService:
error=str(e), tenant_id=str(tenant_id), date=target_date.isoformat())
raise
@transactional
async def create_production_batch(
self,
tenant_id: UUID,
@@ -129,7 +128,6 @@ class ProductionService:
error=str(e), tenant_id=str(tenant_id))
raise
@transactional
async def update_batch_status(
self,
tenant_id: UUID,
@@ -167,7 +165,6 @@ class ProductionService:
error=str(e), batch_id=str(batch_id), tenant_id=str(tenant_id))
raise
@transactional
async def get_dashboard_summary(self, tenant_id: UUID) -> ProductionDashboardSummary:
"""Get production dashboard summary data"""
try:
@@ -215,7 +212,6 @@ class ProductionService:
error=str(e), tenant_id=str(tenant_id))
raise
@transactional
async def get_production_requirements(
self,
tenant_id: UUID,