IMPORVE ONBOARDING STEPS
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
"""make_stock_management_fields_nullable
|
||||
|
||||
Revision ID: make_stock_fields_nullable
|
||||
Revises: add_local_production_support
|
||||
Create Date: 2025-11-08 12:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'make_stock_fields_nullable'
|
||||
down_revision = 'add_local_production_support'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Make stock management fields nullable to simplify onboarding
|
||||
|
||||
These fields (low_stock_threshold, reorder_point, reorder_quantity) are now optional
|
||||
during onboarding and can be configured later based on actual usage patterns.
|
||||
"""
|
||||
|
||||
# Make low_stock_threshold nullable
|
||||
op.alter_column('ingredients', 'low_stock_threshold',
|
||||
existing_type=sa.Float(),
|
||||
nullable=True,
|
||||
existing_nullable=False)
|
||||
|
||||
# Make reorder_point nullable
|
||||
op.alter_column('ingredients', 'reorder_point',
|
||||
existing_type=sa.Float(),
|
||||
nullable=True,
|
||||
existing_nullable=False)
|
||||
|
||||
# Make reorder_quantity nullable
|
||||
op.alter_column('ingredients', 'reorder_quantity',
|
||||
existing_type=sa.Float(),
|
||||
nullable=True,
|
||||
existing_nullable=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Revert stock management fields to NOT NULL
|
||||
|
||||
WARNING: This will fail if any records have NULL values in these fields.
|
||||
You must set default values before running this downgrade.
|
||||
"""
|
||||
|
||||
# Set default values for any NULL records before making fields NOT NULL
|
||||
op.execute("""
|
||||
UPDATE ingredients
|
||||
SET low_stock_threshold = 10.0
|
||||
WHERE low_stock_threshold IS NULL
|
||||
""")
|
||||
|
||||
op.execute("""
|
||||
UPDATE ingredients
|
||||
SET reorder_point = 20.0
|
||||
WHERE reorder_point IS NULL
|
||||
""")
|
||||
|
||||
op.execute("""
|
||||
UPDATE ingredients
|
||||
SET reorder_quantity = 50.0
|
||||
WHERE reorder_quantity IS NULL
|
||||
""")
|
||||
|
||||
# Make fields NOT NULL again
|
||||
op.alter_column('ingredients', 'low_stock_threshold',
|
||||
existing_type=sa.Float(),
|
||||
nullable=False,
|
||||
existing_nullable=True)
|
||||
|
||||
op.alter_column('ingredients', 'reorder_point',
|
||||
existing_type=sa.Float(),
|
||||
nullable=False,
|
||||
existing_nullable=True)
|
||||
|
||||
op.alter_column('ingredients', 'reorder_quantity',
|
||||
existing_type=sa.Float(),
|
||||
nullable=False,
|
||||
existing_nullable=True)
|
||||
Reference in New Issue
Block a user