Add frontend procurement implementation 2

This commit is contained in:
Urtzi Alfaro
2025-09-09 17:40:57 +02:00
parent a290663ec5
commit 23e088dcb4
6 changed files with 339 additions and 75 deletions

View File

@@ -5,6 +5,7 @@ Handles all API calls to the forecasting service
"""
from typing import Dict, Any, Optional, List
from datetime import date
from .base_service_client import BaseServiceClient
from shared.config.base import BaseServiceSettings
@@ -100,6 +101,7 @@ class ForecastServiceClient(BaseServiceClient):
model_id: str,
target_date: str,
features: Dict[str, Any],
inventory_product_id: Optional[str] = None,
**kwargs
) -> Optional[Dict[str, Any]]:
"""Create a real-time prediction"""
@@ -109,7 +111,42 @@ class ForecastServiceClient(BaseServiceClient):
"features": features,
**kwargs
}
return await self.post("predictions", data=data, tenant_id=tenant_id)
# Add inventory_product_id if provided (required by forecasting service)
if inventory_product_id:
data["inventory_product_id"] = inventory_product_id
return await self.post("forecasts/single", data=data, tenant_id=tenant_id)
async def create_single_forecast(
self,
tenant_id: str,
inventory_product_id: str,
forecast_date: date,
location: str = "default",
forecast_days: int = 1,
confidence_level: float = 0.8,
**kwargs
) -> Optional[Dict[str, Any]]:
"""Create a single product forecast using new API format"""
from datetime import date as date_type
# Convert date to string if needed
if isinstance(forecast_date, date_type):
forecast_date_str = forecast_date.isoformat()
else:
forecast_date_str = str(forecast_date)
data = {
"inventory_product_id": inventory_product_id,
"forecast_date": forecast_date_str,
"forecast_days": forecast_days,
"location": location,
"confidence_level": confidence_level,
**kwargs
}
return await self.post("forecasts/single", data=data, tenant_id=tenant_id)
# ================================================================
# FORECAST VALIDATION & METRICS