New enterprise feature

This commit is contained in:
Urtzi Alfaro
2025-11-30 09:12:40 +01:00
parent f9d0eec6ec
commit 972db02f6d
176 changed files with 19741 additions and 1361 deletions

View File

@@ -27,12 +27,16 @@ import random
# Add app to path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
# Add shared to path for demo utilities
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent.parent))
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import select
import structlog
from shared.utils.demo_dates import BASE_REFERENCE_DATE
from app.models.recipes import (
Recipe, RecipeIngredient, ProductionBatch,
RecipeStatus, ProductionStatus, ProductionPriority, MeasurementUnit
@@ -50,8 +54,8 @@ structlog.configure(
logger = structlog.get_logger()
# Fixed Demo Tenant IDs (must match tenant service)
DEMO_TENANT_SAN_PABLO = uuid.UUID("a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6")
DEMO_TENANT_LA_ESPIGA = uuid.UUID("b2c3d4e5-f6a7-48b9-c0d1-e2f3a4b5c6d7")
DEMO_TENANT_PROFESSIONAL = uuid.UUID("a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6")
DEMO_TENANT_ENTERPRISE_CHAIN = uuid.UUID("c3d4e5f6-a7b8-49c0-d1e2-f3a4b5c6d7e8") # Enterprise parent (Obrador)
def load_recipes_data():
@@ -192,9 +196,9 @@ async def seed_recipes_for_tenant(
# Create some sample production batches (historical data)
num_batches = random.randint(3, 8)
for i in range(num_batches):
# Random date in the past 30 days
# Random date in the past 30 days (relative to BASE_REFERENCE_DATE)
days_ago = random.randint(1, 30)
production_date = datetime.now(timezone.utc) - timedelta(days=days_ago)
production_date = BASE_REFERENCE_DATE - timedelta(days=days_ago)
# Random multiplier and quantity
multiplier = random.choice([0.5, 1.0, 1.5, 2.0])
@@ -261,25 +265,25 @@ async def seed_recipes(db: AsyncSession):
results = []
# Seed for San Pablo (Traditional Bakery)
# Seed for Professional Bakery (single location)
logger.info("")
result_san_pablo = await seed_recipes_for_tenant(
result_professional = await seed_recipes_for_tenant(
db,
DEMO_TENANT_SAN_PABLO,
"Panadería San Pablo (Traditional)",
DEMO_TENANT_PROFESSIONAL,
"Panadería Artesana Madrid (Professional)",
recipes_data
)
results.append(result_san_pablo)
results.append(result_professional)
# Seed for La Espiga (Central Workshop)
result_la_espiga = await seed_recipes_for_tenant(
# Seed for Enterprise Parent (central production - Obrador)
logger.info("")
result_enterprise_parent = await seed_recipes_for_tenant(
db,
DEMO_TENANT_LA_ESPIGA,
"Panadería La Espiga (Central Workshop)",
DEMO_TENANT_ENTERPRISE_CHAIN,
"Panadería Central - Obrador Madrid (Enterprise Parent)",
recipes_data
)
results.append(result_la_espiga)
results.append(result_enterprise_parent)
# Calculate totals
total_recipes = sum(r["recipes_created"] for r in results)
total_ingredients = sum(r["recipe_ingredients_created"] for r in results)