New enterprise feature2
This commit is contained in:
@@ -28,10 +28,9 @@ from shared.clients import (
|
||||
get_production_client,
|
||||
get_sales_client,
|
||||
get_inventory_client,
|
||||
get_procurement_client
|
||||
get_procurement_client,
|
||||
get_distribution_client
|
||||
)
|
||||
# TODO: Add distribution client when available
|
||||
# from shared.clients import get_distribution_client
|
||||
|
||||
def get_enterprise_dashboard_service() -> EnterpriseDashboardService:
|
||||
from app.core.config import settings
|
||||
@@ -40,7 +39,7 @@ def get_enterprise_dashboard_service() -> EnterpriseDashboardService:
|
||||
production_client = get_production_client(settings)
|
||||
sales_client = get_sales_client(settings)
|
||||
inventory_client = get_inventory_client(settings)
|
||||
distribution_client = None # TODO: Add when distribution service is ready
|
||||
distribution_client = get_distribution_client(settings)
|
||||
procurement_client = get_procurement_client(settings)
|
||||
|
||||
return EnterpriseDashboardService(
|
||||
|
||||
@@ -110,7 +110,8 @@ from shared.clients import (
|
||||
get_production_client,
|
||||
get_sales_client,
|
||||
get_inventory_client,
|
||||
get_procurement_client
|
||||
get_procurement_client,
|
||||
get_distribution_client
|
||||
)
|
||||
|
||||
def get_enterprise_dashboard_service() -> EnterpriseDashboardService:
|
||||
@@ -119,7 +120,7 @@ def get_enterprise_dashboard_service() -> EnterpriseDashboardService:
|
||||
production_client = get_production_client(settings)
|
||||
sales_client = get_sales_client(settings)
|
||||
inventory_client = get_inventory_client(settings)
|
||||
distribution_client = None # TODO: Add when distribution service is ready
|
||||
distribution_client = get_distribution_client(settings)
|
||||
procurement_client = get_procurement_client(settings)
|
||||
|
||||
return EnterpriseDashboardService(
|
||||
|
||||
@@ -138,13 +138,8 @@ class EnterpriseDashboardService:
|
||||
async def _get_production_volume(self, parent_tenant_id: str) -> float:
|
||||
"""Get total production volume for the parent tenant (central production)"""
|
||||
try:
|
||||
start_date = date.today() - timedelta(days=30)
|
||||
end_date = date.today()
|
||||
|
||||
production_summary = await self.production_client.get_production_summary(
|
||||
tenant_id=parent_tenant_id,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
production_summary = await self.production_client.get_dashboard_summary(
|
||||
tenant_id=parent_tenant_id
|
||||
)
|
||||
|
||||
# Return total production value
|
||||
@@ -382,6 +377,16 @@ class EnterpriseDashboardService:
|
||||
total_demand = 0
|
||||
daily_summary = {}
|
||||
|
||||
if not forecast_data:
|
||||
logger.warning("No forecast data returned", parent_tenant_id=parent_tenant_id)
|
||||
return {
|
||||
'parent_tenant_id': parent_tenant_id,
|
||||
'days_forecast': days_ahead,
|
||||
'total_predicted_demand': 0,
|
||||
'daily_summary': {},
|
||||
'last_updated': datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
for forecast_date_str, products in forecast_data.get('aggregated_forecasts', {}).items():
|
||||
day_total = sum(item.get('predicted_demand', 0) for item in products.values())
|
||||
total_demand += day_total
|
||||
@@ -500,10 +505,8 @@ class EnterpriseDashboardService:
|
||||
async def _get_tenant_production(self, tenant_id: str, start_date: date, end_date: date) -> float:
|
||||
"""Helper to get production for a specific tenant"""
|
||||
try:
|
||||
production_data = await self.production_client.get_production_summary(
|
||||
tenant_id=tenant_id,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
production_data = await self.production_client.get_dashboard_summary(
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
return float(production_data.get('total_value', 0))
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user