Start integrating the onboarding flow with backend 12

This commit is contained in:
Urtzi Alfaro
2025-09-07 17:25:30 +02:00
parent 9005286ada
commit b73f3b4993
32 changed files with 3172 additions and 3087 deletions

View File

@@ -38,20 +38,22 @@ class UpdateStepRequest(BaseModel):
completed: bool
data: Optional[Dict[str, Any]] = None
# Define the onboarding steps and their order
# Define the onboarding steps and their order - matching frontend step IDs
ONBOARDING_STEPS = [
"user_registered", # Step 1: User account created
"bakery_registered", # Step 2: Bakery/tenant created
"sales_data_uploaded", # Step 3: Historical sales data uploaded
"training_completed", # Step 4: AI model training completed
"dashboard_accessible" # Step 5: Ready to use dashboard
"user_registered", # Auto-completed: User account created
"setup", # Step 1: Basic bakery setup and tenant creation
"smart-inventory-setup", # Step 2: Sales data upload and inventory configuration
"suppliers", # Step 3: Suppliers configuration (optional)
"ml-training", # Step 4: AI model training
"completion" # Step 5: Onboarding completed, ready to use dashboard
]
STEP_DEPENDENCIES = {
"bakery_registered": ["user_registered"],
"sales_data_uploaded": ["user_registered", "bakery_registered"],
"training_completed": ["user_registered", "bakery_registered", "sales_data_uploaded"],
"dashboard_accessible": ["user_registered", "bakery_registered", "sales_data_uploaded", "training_completed"]
"setup": ["user_registered"],
"smart-inventory-setup": ["user_registered", "setup"],
"suppliers": ["user_registered", "setup", "smart-inventory-setup"], # Optional step
"ml-training": ["user_registered", "setup", "smart-inventory-setup"],
"completion": ["user_registered", "setup", "smart-inventory-setup", "ml-training"]
}
class OnboardingService:
@@ -216,6 +218,30 @@ class OnboardingService:
if not user_progress_data.get(required_step, {}).get("completed", False):
return False
# SPECIAL VALIDATION FOR ML TRAINING STEP
if step_name == "ml-training":
# Ensure that smart-inventory-setup was completed with sales data imported
smart_inventory_data = user_progress_data.get("smart-inventory-setup", {}).get("data", {})
# Check if sales data was imported successfully
sales_import_result = smart_inventory_data.get("salesImportResult", {})
has_sales_data_imported = (
sales_import_result.get("records_created", 0) > 0 or
sales_import_result.get("success", False) or
sales_import_result.get("imported", False)
)
if not has_sales_data_imported:
logger.warning(f"ML training blocked for user {user_id}: No sales data imported",
extra={"sales_import_result": sales_import_result})
return False
# Also check if inventory is configured
inventory_configured = smart_inventory_data.get("inventoryConfigured", False)
if not inventory_configured:
logger.warning(f"ML training blocked for user {user_id}: Inventory not configured")
return False
return True
async def _get_user_onboarding_data(self, user_id: str) -> Dict[str, Any]: