demo seed change 4
This commit is contained in:
@@ -157,21 +157,18 @@ async def trigger_safety_stock_optimization(
|
||||
|
||||
try:
|
||||
# Fetch sales data for this product
|
||||
sales_response = await sales_client.get_sales_data(
|
||||
sales_data = await sales_client.get_sales_data(
|
||||
tenant_id=tenant_id,
|
||||
product_id=product_id,
|
||||
start_date=start_date.strftime('%Y-%m-%d'),
|
||||
end_date=end_date.strftime('%Y-%m-%d')
|
||||
)
|
||||
|
||||
if not sales_response or not sales_response.get('sales'):
|
||||
if not sales_data:
|
||||
logger.warning(
|
||||
f"No sales history for product {product_id}, skipping"
|
||||
)
|
||||
continue
|
||||
|
||||
# Convert sales data to daily demand
|
||||
sales_data = sales_response.get('sales', [])
|
||||
demand_data = []
|
||||
|
||||
for sale in sales_data:
|
||||
|
||||
@@ -179,8 +179,21 @@ class InventoryScheduler:
|
||||
|
||||
for shortage in stock_shortages:
|
||||
try:
|
||||
ingredient_id = UUID(shortage["ingredient_id"])
|
||||
tenant_id = UUID(shortage["tenant_id"])
|
||||
# Handle asyncpg UUID objects properly
|
||||
ingredient_id_val = shortage["ingredient_id"]
|
||||
tenant_id_val = shortage["tenant_id"]
|
||||
|
||||
# Convert asyncpg UUID to string first, then to UUID
|
||||
if hasattr(ingredient_id_val, 'hex'):
|
||||
ingredient_id = UUID(hex=ingredient_id_val.hex)
|
||||
else:
|
||||
ingredient_id = UUID(str(ingredient_id_val))
|
||||
|
||||
if hasattr(tenant_id_val, 'hex'):
|
||||
tenant_id = UUID(hex=tenant_id_val.hex)
|
||||
else:
|
||||
tenant_id = UUID(str(tenant_id_val))
|
||||
|
||||
current_quantity = float(shortage["current_quantity"])
|
||||
required_quantity = float(shortage["required_quantity"])
|
||||
shortage_amount = float(shortage["shortage_amount"])
|
||||
@@ -515,7 +528,12 @@ class InventoryScheduler:
|
||||
|
||||
for shortage in critical_shortages:
|
||||
try:
|
||||
ingredient_id = UUID(str(shortage["id"])) # Use 'id' instead of 'ingredient_id'
|
||||
# Handle asyncpg UUID objects properly
|
||||
ingredient_id_val = shortage["id"]
|
||||
if hasattr(ingredient_id_val, 'hex'):
|
||||
ingredient_id = UUID(hex=ingredient_id_val.hex)
|
||||
else:
|
||||
ingredient_id = UUID(str(ingredient_id_val))
|
||||
|
||||
# Extract values with defaults
|
||||
current_quantity = float(shortage.get("current_stock", 0))
|
||||
@@ -732,8 +750,19 @@ class InventoryScheduler:
|
||||
|
||||
for shortage in critical_shortages:
|
||||
try:
|
||||
ingredient_id = UUID(str(shortage["id"]))
|
||||
tenant_id = UUID(shortage["tenant_id"])
|
||||
# Handle asyncpg UUID objects properly
|
||||
ingredient_id_val = shortage["id"]
|
||||
tenant_id_val = shortage["tenant_id"]
|
||||
|
||||
if hasattr(ingredient_id_val, 'hex'):
|
||||
ingredient_id = UUID(hex=ingredient_id_val.hex)
|
||||
else:
|
||||
ingredient_id = UUID(str(ingredient_id_val))
|
||||
|
||||
if hasattr(tenant_id_val, 'hex'):
|
||||
tenant_id = UUID(hex=tenant_id_val.hex)
|
||||
else:
|
||||
tenant_id = UUID(str(tenant_id_val))
|
||||
|
||||
# Extract values with defaults
|
||||
current_quantity = float(shortage.get("current_stock", 0))
|
||||
|
||||
Reference in New Issue
Block a user