IMPORVE ONBOARDING STEPS

This commit is contained in:
Urtzi Alfaro
2025-11-09 09:22:08 +01:00
parent 4678f96f8f
commit cbe19a3cd1
27 changed files with 2801 additions and 1149 deletions

View File

@@ -114,10 +114,11 @@ class Ingredient(Base):
last_purchase_price = Column(Numeric(10, 2), nullable=True)
standard_cost = Column(Numeric(10, 2), nullable=True)
# Stock management
low_stock_threshold = Column(Float, nullable=False, default=10.0)
reorder_point = Column(Float, nullable=False, default=20.0)
reorder_quantity = Column(Float, nullable=False, default=50.0)
# Stock management - now optional to simplify onboarding
# These can be configured later based on actual usage patterns
low_stock_threshold = Column(Float, nullable=True, default=None)
reorder_point = Column(Float, nullable=True, default=None)
reorder_quantity = Column(Float, nullable=True, default=None)
max_stock_level = Column(Float, nullable=True)
# Shelf life (critical for finished products) - default values only

View File

@@ -46,12 +46,14 @@ class IngredientCreate(InventoryBaseSchema):
# Pricing
# Note: average_cost is calculated automatically from purchases (not set on create)
# All cost fields are optional - can be added later after onboarding
standard_cost: Optional[Decimal] = Field(None, ge=0, description="Standard/target cost per unit for budgeting")
# Stock management
low_stock_threshold: float = Field(10.0, ge=0, description="Low stock alert threshold")
reorder_point: float = Field(20.0, ge=0, description="Reorder point")
reorder_quantity: float = Field(50.0, gt=0, description="Default reorder quantity")
# Stock management - all optional with sensible defaults for onboarding
# These can be configured later based on actual usage patterns
low_stock_threshold: Optional[float] = Field(None, ge=0, description="Low stock alert threshold")
reorder_point: Optional[float] = Field(None, ge=0, description="Reorder point")
reorder_quantity: Optional[float] = Field(None, gt=0, description="Default reorder quantity")
max_stock_level: Optional[float] = Field(None, gt=0, description="Maximum stock level")
# Shelf life (default value only - actual per batch)
@@ -67,8 +69,15 @@ class IngredientCreate(InventoryBaseSchema):
@validator('reorder_point')
def validate_reorder_point(cls, v, values):
if 'low_stock_threshold' in values and v <= values['low_stock_threshold']:
raise ValueError('Reorder point must be greater than low stock threshold')
# Only validate if both values are provided and not None
low_stock = values.get('low_stock_threshold')
if v is not None and low_stock is not None:
try:
if v <= low_stock:
raise ValueError('Reorder point must be greater than low stock threshold')
except TypeError:
# Skip validation if comparison fails due to type mismatch
pass
return v
@@ -125,9 +134,9 @@ class IngredientResponse(InventoryBaseSchema):
average_cost: Optional[float]
last_purchase_price: Optional[float]
standard_cost: Optional[float]
low_stock_threshold: float
reorder_point: float
reorder_quantity: float
low_stock_threshold: Optional[float] # Now optional
reorder_point: Optional[float] # Now optional
reorder_quantity: Optional[float] # Now optional
max_stock_level: Optional[float]
shelf_life_days: Optional[int] # Default value only
is_active: bool
@@ -209,9 +218,15 @@ class StockCreate(InventoryBaseSchema):
@validator('storage_temperature_max')
def validate_temperature_range(cls, v, values):
# Only validate if both values are provided and not None
min_temp = values.get('storage_temperature_min')
if v is not None and min_temp is not None and v <= min_temp:
raise ValueError('Max temperature must be greater than min temperature')
if v is not None and min_temp is not None:
try:
if v <= min_temp:
raise ValueError('Max temperature must be greater than min temperature')
except TypeError:
# Skip validation if comparison fails due to type mismatch
pass
return v
class StockUpdate(InventoryBaseSchema):

View File

@@ -1062,9 +1062,12 @@ class InventoryService:
async def _validate_ingredient_data(self, ingredient_data: IngredientCreate, tenant_id: UUID):
"""Validate ingredient data for business rules"""
# Add business validation logic here
if ingredient_data.reorder_point <= ingredient_data.low_stock_threshold:
raise ValueError("Reorder point must be greater than low stock threshold")
# Only validate reorder_point if both values are provided
# During onboarding, these fields may be None, which is valid
if (ingredient_data.reorder_point is not None and
ingredient_data.low_stock_threshold is not None):
if ingredient_data.reorder_point <= ingredient_data.low_stock_threshold:
raise ValueError("Reorder point must be greater than low stock threshold")
# Storage requirements validation moved to stock level (not ingredient level)
# This is now handled in stock creation/update validation