Fix AI insights feature issues

This commit is contained in:
Urtzi Alfaro
2025-12-16 13:32:33 +01:00
parent b43648e0f8
commit 0bbfa010bf
5 changed files with 576 additions and 55 deletions

View File

@@ -274,6 +274,56 @@ class SalesServiceClient(BaseServiceClient):
)
return {}
async def get_product_demand_patterns(
self,
tenant_id: str,
product_id: str,
start_date: Optional[date] = None,
end_date: Optional[date] = None,
min_history_days: int = 90
) -> Dict[str, Any]:
"""
Get demand pattern analysis for a specific product.
Args:
tenant_id: Tenant identifier
product_id: Product identifier (inventory_product_id)
start_date: Start date for analysis
end_date: End date for analysis
min_history_days: Minimum days of history required
Returns:
Demand pattern analysis including trends, seasonality, and statistics
"""
try:
params = {"min_history_days": min_history_days}
if start_date:
params["start_date"] = start_date.isoformat()
if end_date:
params["end_date"] = end_date.isoformat()
result = await self.get(
f"sales/analytics/products/{product_id}/demand-patterns",
tenant_id=tenant_id,
params=params
)
logger.info(
"Retrieved product demand patterns",
tenant_id=tenant_id,
product_id=product_id
)
return result if result else {}
except Exception as e:
logger.error(
"Failed to get product demand patterns",
error=str(e),
tenant_id=tenant_id,
product_id=product_id
)
return {}
# ================================================================
# DATA IMPORT
# ================================================================