Improve the frontend and repository layer
This commit is contained in:
181
services/tenant/app/schemas/tenant_settings.py
Normal file
181
services/tenant/app/schemas/tenant_settings.py
Normal file
@@ -0,0 +1,181 @@
|
||||
# services/tenant/app/schemas/tenant_settings.py
|
||||
"""
|
||||
Tenant Settings Schemas
|
||||
Pydantic models for API request/response validation
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
# ================================================================
|
||||
# SETTING CATEGORY SCHEMAS
|
||||
# ================================================================
|
||||
|
||||
class ProcurementSettings(BaseModel):
|
||||
"""Procurement and auto-approval settings"""
|
||||
auto_approve_enabled: bool = True
|
||||
auto_approve_threshold_eur: float = Field(500.0, ge=0, le=10000)
|
||||
auto_approve_min_supplier_score: float = Field(0.80, ge=0.0, le=1.0)
|
||||
require_approval_new_suppliers: bool = True
|
||||
require_approval_critical_items: bool = True
|
||||
procurement_lead_time_days: int = Field(3, ge=1, le=30)
|
||||
demand_forecast_days: int = Field(14, ge=1, le=90)
|
||||
safety_stock_percentage: float = Field(20.0, ge=0.0, le=100.0)
|
||||
po_approval_reminder_hours: int = Field(24, ge=1, le=168)
|
||||
po_critical_escalation_hours: int = Field(12, ge=1, le=72)
|
||||
|
||||
|
||||
class InventorySettings(BaseModel):
|
||||
"""Inventory management settings"""
|
||||
low_stock_threshold: int = Field(10, ge=1, le=1000)
|
||||
reorder_point: int = Field(20, ge=1, le=1000)
|
||||
reorder_quantity: int = Field(50, ge=1, le=1000)
|
||||
expiring_soon_days: int = Field(7, ge=1, le=30)
|
||||
expiration_warning_days: int = Field(3, ge=1, le=14)
|
||||
quality_score_threshold: float = Field(8.0, ge=0.0, le=10.0)
|
||||
temperature_monitoring_enabled: bool = True
|
||||
refrigeration_temp_min: float = Field(1.0, ge=-5.0, le=10.0)
|
||||
refrigeration_temp_max: float = Field(4.0, ge=-5.0, le=10.0)
|
||||
freezer_temp_min: float = Field(-20.0, ge=-30.0, le=0.0)
|
||||
freezer_temp_max: float = Field(-15.0, ge=-30.0, le=0.0)
|
||||
room_temp_min: float = Field(18.0, ge=10.0, le=35.0)
|
||||
room_temp_max: float = Field(25.0, ge=10.0, le=35.0)
|
||||
temp_deviation_alert_minutes: int = Field(15, ge=1, le=60)
|
||||
critical_temp_deviation_minutes: int = Field(5, ge=1, le=30)
|
||||
|
||||
@validator('refrigeration_temp_max')
|
||||
def validate_refrigeration_range(cls, v, values):
|
||||
if 'refrigeration_temp_min' in values and v <= values['refrigeration_temp_min']:
|
||||
raise ValueError('refrigeration_temp_max must be greater than refrigeration_temp_min')
|
||||
return v
|
||||
|
||||
@validator('freezer_temp_max')
|
||||
def validate_freezer_range(cls, v, values):
|
||||
if 'freezer_temp_min' in values and v <= values['freezer_temp_min']:
|
||||
raise ValueError('freezer_temp_max must be greater than freezer_temp_min')
|
||||
return v
|
||||
|
||||
@validator('room_temp_max')
|
||||
def validate_room_range(cls, v, values):
|
||||
if 'room_temp_min' in values and v <= values['room_temp_min']:
|
||||
raise ValueError('room_temp_max must be greater than room_temp_min')
|
||||
return v
|
||||
|
||||
|
||||
class ProductionSettings(BaseModel):
|
||||
"""Production settings"""
|
||||
planning_horizon_days: int = Field(7, ge=1, le=30)
|
||||
minimum_batch_size: float = Field(1.0, ge=0.1, le=100.0)
|
||||
maximum_batch_size: float = Field(100.0, ge=1.0, le=1000.0)
|
||||
production_buffer_percentage: float = Field(10.0, ge=0.0, le=50.0)
|
||||
working_hours_per_day: int = Field(12, ge=1, le=24)
|
||||
max_overtime_hours: int = Field(4, ge=0, le=12)
|
||||
capacity_utilization_target: float = Field(0.85, ge=0.5, le=1.0)
|
||||
capacity_warning_threshold: float = Field(0.95, ge=0.7, le=1.0)
|
||||
quality_check_enabled: bool = True
|
||||
minimum_yield_percentage: float = Field(85.0, ge=50.0, le=100.0)
|
||||
quality_score_threshold: float = Field(8.0, ge=0.0, le=10.0)
|
||||
schedule_optimization_enabled: bool = True
|
||||
prep_time_buffer_minutes: int = Field(30, ge=0, le=120)
|
||||
cleanup_time_buffer_minutes: int = Field(15, ge=0, le=120)
|
||||
labor_cost_per_hour_eur: float = Field(15.0, ge=5.0, le=100.0)
|
||||
overhead_cost_percentage: float = Field(20.0, ge=0.0, le=50.0)
|
||||
|
||||
@validator('maximum_batch_size')
|
||||
def validate_batch_size_range(cls, v, values):
|
||||
if 'minimum_batch_size' in values and v <= values['minimum_batch_size']:
|
||||
raise ValueError('maximum_batch_size must be greater than minimum_batch_size')
|
||||
return v
|
||||
|
||||
@validator('capacity_warning_threshold')
|
||||
def validate_capacity_threshold(cls, v, values):
|
||||
if 'capacity_utilization_target' in values and v <= values['capacity_utilization_target']:
|
||||
raise ValueError('capacity_warning_threshold must be greater than capacity_utilization_target')
|
||||
return v
|
||||
|
||||
|
||||
class SupplierSettings(BaseModel):
|
||||
"""Supplier management settings"""
|
||||
default_payment_terms_days: int = Field(30, ge=1, le=90)
|
||||
default_delivery_days: int = Field(3, ge=1, le=30)
|
||||
excellent_delivery_rate: float = Field(95.0, ge=90.0, le=100.0)
|
||||
good_delivery_rate: float = Field(90.0, ge=80.0, le=99.0)
|
||||
excellent_quality_rate: float = Field(98.0, ge=90.0, le=100.0)
|
||||
good_quality_rate: float = Field(95.0, ge=80.0, le=99.0)
|
||||
critical_delivery_delay_hours: int = Field(24, ge=1, le=168)
|
||||
critical_quality_rejection_rate: float = Field(10.0, ge=0.0, le=50.0)
|
||||
high_cost_variance_percentage: float = Field(15.0, ge=0.0, le=100.0)
|
||||
|
||||
@validator('good_delivery_rate')
|
||||
def validate_delivery_rates(cls, v, values):
|
||||
if 'excellent_delivery_rate' in values and v >= values['excellent_delivery_rate']:
|
||||
raise ValueError('good_delivery_rate must be less than excellent_delivery_rate')
|
||||
return v
|
||||
|
||||
@validator('good_quality_rate')
|
||||
def validate_quality_rates(cls, v, values):
|
||||
if 'excellent_quality_rate' in values and v >= values['excellent_quality_rate']:
|
||||
raise ValueError('good_quality_rate must be less than excellent_quality_rate')
|
||||
return v
|
||||
|
||||
|
||||
class POSSettings(BaseModel):
|
||||
"""POS integration settings"""
|
||||
sync_interval_minutes: int = Field(5, ge=1, le=60)
|
||||
auto_sync_products: bool = True
|
||||
auto_sync_transactions: bool = True
|
||||
|
||||
|
||||
class OrderSettings(BaseModel):
|
||||
"""Order and business rules settings"""
|
||||
max_discount_percentage: float = Field(50.0, ge=0.0, le=100.0)
|
||||
default_delivery_window_hours: int = Field(48, ge=1, le=168)
|
||||
dynamic_pricing_enabled: bool = False
|
||||
discount_enabled: bool = True
|
||||
delivery_tracking_enabled: bool = True
|
||||
|
||||
|
||||
# ================================================================
|
||||
# REQUEST/RESPONSE SCHEMAS
|
||||
# ================================================================
|
||||
|
||||
class TenantSettingsResponse(BaseModel):
|
||||
"""Response schema for tenant settings"""
|
||||
id: UUID
|
||||
tenant_id: UUID
|
||||
procurement_settings: ProcurementSettings
|
||||
inventory_settings: InventorySettings
|
||||
production_settings: ProductionSettings
|
||||
supplier_settings: SupplierSettings
|
||||
pos_settings: POSSettings
|
||||
order_settings: OrderSettings
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class TenantSettingsUpdate(BaseModel):
|
||||
"""Schema for updating tenant settings"""
|
||||
procurement_settings: Optional[ProcurementSettings] = None
|
||||
inventory_settings: Optional[InventorySettings] = None
|
||||
production_settings: Optional[ProductionSettings] = None
|
||||
supplier_settings: Optional[SupplierSettings] = None
|
||||
pos_settings: Optional[POSSettings] = None
|
||||
order_settings: Optional[OrderSettings] = None
|
||||
|
||||
|
||||
class CategoryUpdateRequest(BaseModel):
|
||||
"""Schema for updating a single category"""
|
||||
settings: dict
|
||||
|
||||
|
||||
class CategoryResetResponse(BaseModel):
|
||||
"""Response schema for category reset"""
|
||||
category: str
|
||||
settings: dict
|
||||
message: str
|
||||
Reference in New Issue
Block a user