Fix onboarding API dependencies after removing manual path
**Root Cause:** Frontend removed data-source-choice step and manual path, but backend still required data-source-choice as dependency for smart-inventory-setup. This caused: "Cannot complete step smart-inventory-setup: dependencies not met" **Changes:** 1. **Removed data-source-choice step** (line 48) - No longer in ONBOARDING_STEPS list - AI-assisted is now the only path 2. **Updated setup dependencies** (line 79) - Before: "setup": ["user_registered", "data-source-choice"] - After: "setup": ["user_registered", "bakery-type-selection"] - Removed dependency on non-existent step 3. **Removed manual path steps** - Removed "inventory-setup" from ONBOARDING_STEPS - Kept only AI-assisted path steps 4. **Updated suppliers dependencies** (line 87) - Now requires "smart-inventory-setup" completion - Makes logical sense: need inventory before suppliers 5. **Simplified ML training validation** (lines 278-299) - Removed manual path check (inventory-setup) - Only validates AI path (smart-inventory-setup) - Cleaner logic without dual-path complexity **Step Order (Updated):** ``` 1. user_registered 2. bakery-type-selection 3. setup (tenant creation) 4. smart-inventory-setup (AI inventory) 5. product-categorization 6. initial-stock-entry 7. suppliers-setup 8. recipes-setup (optional) 9. production-processes (optional) 10. quality-setup (optional) 11. team-setup (optional) 12. ml-training 13. setup-review 14. completion ``` **Dependency Chain (Fixed):** ``` smart-inventory-setup → setup → bakery-type-selection → user_registered (was broken: smart-inventory-setup → setup → data-source-choice [MISSING!]) ``` **Files Modified:** - services/auth/app/api/onboarding_progress.py:42-101,278-299 **Impact:** ✅ Onboarding steps now work correctly from initial bakery registration ✅ No more "dependencies not met" errors ✅ Backend matches frontend architecture
This commit is contained in:
@@ -45,23 +45,21 @@ ONBOARDING_STEPS = [
|
||||
|
||||
# Phase 1: Discovery
|
||||
"bakery-type-selection", # Choose bakery type: production/retail/mixed
|
||||
"data-source-choice", # Choose setup method: AI-assisted or manual
|
||||
|
||||
# Phase 2: Core Setup
|
||||
"setup", # Basic bakery setup and tenant creation
|
||||
|
||||
# Phase 2a: AI-Assisted Path
|
||||
# Phase 2a: AI-Assisted Path (ONLY PATH - manual path removed)
|
||||
"smart-inventory-setup", # Sales data upload and AI analysis
|
||||
"product-categorization", # Categorize products as ingredients vs finished products
|
||||
"initial-stock-entry", # Capture initial stock levels
|
||||
|
||||
# Phase 2b: Manual Setup Path
|
||||
# Phase 2b: Suppliers (shared by all paths)
|
||||
"suppliers-setup", # Suppliers configuration
|
||||
"inventory-setup", # Manual inventory configuration
|
||||
|
||||
# Phase 3: Advanced Configuration (all optional)
|
||||
"recipes-setup", # Production recipes (conditional: production/mixed bakery)
|
||||
"production-processes", # Finishing processes (conditional: retail/mixed bakery)
|
||||
|
||||
# Phase 3: Advanced Configuration
|
||||
"quality-setup", # Quality standards and templates
|
||||
"team-setup", # Team members and permissions
|
||||
|
||||
@@ -75,28 +73,27 @@ ONBOARDING_STEPS = [
|
||||
# Steps not listed here have no dependencies (can be completed anytime after user_registered)
|
||||
STEP_DEPENDENCIES = {
|
||||
# Discovery phase
|
||||
"data-source-choice": ["user_registered", "bakery-type-selection"],
|
||||
"bakery-type-selection": ["user_registered"],
|
||||
|
||||
# Core setup
|
||||
"setup": ["user_registered", "data-source-choice"],
|
||||
# Core setup - no longer depends on data-source-choice (removed)
|
||||
"setup": ["user_registered", "bakery-type-selection"],
|
||||
|
||||
# AI-Assisted path dependencies
|
||||
# AI-Assisted path dependencies (ONLY path now)
|
||||
"smart-inventory-setup": ["user_registered", "setup"],
|
||||
"product-categorization": ["user_registered", "setup", "smart-inventory-setup"],
|
||||
"initial-stock-entry": ["user_registered", "setup", "smart-inventory-setup", "product-categorization"],
|
||||
|
||||
# Manual path dependencies
|
||||
"suppliers-setup": ["user_registered", "setup"],
|
||||
"inventory-setup": ["user_registered", "setup"],
|
||||
# Suppliers (after AI inventory setup)
|
||||
"suppliers-setup": ["user_registered", "setup", "smart-inventory-setup"],
|
||||
|
||||
# Advanced configuration (optional, minimal dependencies)
|
||||
"recipes-setup": ["user_registered", "setup"],
|
||||
"production-processes": ["user_registered", "setup"],
|
||||
|
||||
# Advanced configuration
|
||||
"quality-setup": ["user_registered", "setup"],
|
||||
"team-setup": ["user_registered", "setup"],
|
||||
|
||||
# ML Training - requires either AI path or manual inventory
|
||||
"ml-training": ["user_registered", "setup"], # Flexible: can work with either path
|
||||
# ML Training - requires AI path completion
|
||||
"ml-training": ["user_registered", "setup", "smart-inventory-setup"],
|
||||
|
||||
# Review and completion
|
||||
"setup-review": ["user_registered", "setup"],
|
||||
@@ -280,14 +277,11 @@ class OnboardingService:
|
||||
|
||||
# SPECIAL VALIDATION FOR ML TRAINING STEP
|
||||
if step_name == "ml-training":
|
||||
# ML training can work with either AI-assisted path or manual inventory path
|
||||
# Check if user has data through either path
|
||||
|
||||
# ML training requires AI-assisted path completion (only path available now)
|
||||
ai_path_complete = user_progress_data.get("smart-inventory-setup", {}).get("completed", False)
|
||||
manual_path_complete = user_progress_data.get("inventory-setup", {}).get("completed", False)
|
||||
|
||||
if ai_path_complete:
|
||||
# AI path: validate sales data was imported
|
||||
# Validate sales data was imported
|
||||
smart_inventory_data = user_progress_data.get("smart-inventory-setup", {}).get("data", {})
|
||||
sales_import_result = smart_inventory_data.get("salesImportResult", {})
|
||||
has_sales_data_imported = (
|
||||
@@ -300,13 +294,8 @@ class OnboardingService:
|
||||
logger.info(f"ML training allowed for user {user_id}: AI path with sales data")
|
||||
return True
|
||||
|
||||
if manual_path_complete:
|
||||
# Manual path: just check if inventory setup was completed
|
||||
logger.info(f"ML training allowed for user {user_id}: Manual inventory path")
|
||||
return True
|
||||
|
||||
# Neither path is complete
|
||||
logger.warning(f"ML training blocked for user {user_id}: No inventory data (AI or manual)")
|
||||
# AI path not complete or no sales data
|
||||
logger.warning(f"ML training blocked for user {user_id}: No inventory data from AI path")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user