diff --git a/services/orchestrator/app/services/dashboard_service.py b/services/orchestrator/app/services/dashboard_service.py index 099a1813..4d667221 100644 --- a/services/orchestrator/app/services/dashboard_service.py +++ b/services/orchestrator/app/services/dashboard_service.py @@ -602,6 +602,7 @@ class DashboardService: "parameters": { "product_name": batch.get("product_name", "Product"), "predicted_demand": batch.get("planned_quantity", 0), + "current_stock": 0, # Default to 0 if not available "confidence_score": 85 } } diff --git a/services/production/app/services/production_service.py b/services/production/app/services/production_service.py index c54b0c45..041a6907 100644 --- a/services/production/app/services/production_service.py +++ b/services/production/app/services/production_service.py @@ -1839,8 +1839,15 @@ class ProductionService: # Generate reasoning data for JTBD dashboard from shared.schemas.reasoning_types import create_batch_reasoning_forecast_demand + # Try to get product name from forecast, stock_info, or use placeholder + product_name = ( + forecast.get('product_name') or + (stock_info.get('product_name') if stock_info else None) or + f"Product {product_id}" + ) + reasoning_data = create_batch_reasoning_forecast_demand( - product_name=f"Product {product_id}", # TODO: Get actual product name from inventory + product_name=product_name, predicted_demand=predicted_demand, current_stock=current_stock, production_needed=production_needed, @@ -1849,16 +1856,23 @@ class ProductionService: ) # Create production batch + planned_start = datetime.combine(target_date, datetime.min.time()) + planned_end = datetime.combine(target_date, datetime.max.time()) + duration_minutes = int((planned_end - planned_start).total_seconds() / 60) + batch_data = { 'tenant_id': tenant_id, 'schedule_id': schedule.id, + 'product_id': product_id, # Product ID from forecast + 'product_name': product_name, # Product name resolved above 'recipe_id': product_id, # Assuming recipe_id matches product_id 'batch_number': await self._generate_batch_number(session, tenant_id, target_date, batches_created + 1), 'status': 'scheduled', 'priority': 'normal', - 'planned_start_time': datetime.combine(target_date, datetime.min.time()), - 'planned_end_time': datetime.combine(target_date, datetime.max.time()), + 'planned_start_time': planned_start, + 'planned_end_time': planned_end, 'planned_quantity': production_needed, + 'planned_duration_minutes': duration_minutes, 'reasoning_data': reasoning_data, # NEW: Structured reasoning for i18n 'created_at': datetime.now(timezone.utc), 'updated_at': datetime.now(timezone.utc),