Improve the frontend 3
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
"""add missing settings columns to tenant settings
|
||||
|
||||
Revision ID: 20251030_add_missing_settings
|
||||
Revises: 20251028_remove_sub_tier
|
||||
Create Date: 2025-10-30
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from uuid import uuid4
|
||||
import json
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '20251030_add_missing_settings'
|
||||
down_revision = '20251028_remove_sub_tier'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def get_default_settings():
|
||||
"""Get default settings for the new categories"""
|
||||
return {
|
||||
"replenishment_settings": {
|
||||
"projection_horizon_days": 7,
|
||||
"service_level": 0.95,
|
||||
"buffer_days": 1,
|
||||
"enable_auto_replenishment": True,
|
||||
"min_order_quantity": 1.0,
|
||||
"max_order_quantity": 1000.0,
|
||||
"demand_forecast_days": 14
|
||||
},
|
||||
"safety_stock_settings": {
|
||||
"service_level": 0.95,
|
||||
"method": "statistical",
|
||||
"min_safety_stock": 0.0,
|
||||
"max_safety_stock": 100.0,
|
||||
"reorder_point_calculation": "safety_stock_plus_lead_time_demand"
|
||||
},
|
||||
"moq_settings": {
|
||||
"consolidation_window_days": 7,
|
||||
"allow_early_ordering": True,
|
||||
"enable_batch_optimization": True,
|
||||
"min_batch_size": 1.0,
|
||||
"max_batch_size": 1000.0
|
||||
},
|
||||
"supplier_selection_settings": {
|
||||
"price_weight": 0.40,
|
||||
"lead_time_weight": 0.20,
|
||||
"quality_weight": 0.20,
|
||||
"reliability_weight": 0.20,
|
||||
"diversification_threshold": 1000,
|
||||
"max_single_percentage": 0.70,
|
||||
"enable_supplier_score_optimization": True
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Add missing settings columns to tenant_settings table"""
|
||||
# Add the missing columns with default values
|
||||
default_settings = get_default_settings()
|
||||
|
||||
# Add replenishment_settings column
|
||||
op.add_column('tenant_settings',
|
||||
sa.Column('replenishment_settings', postgresql.JSON(),
|
||||
nullable=False,
|
||||
server_default=str(default_settings["replenishment_settings"]).replace("'", '"').replace("True", "true").replace("False", "false"))
|
||||
)
|
||||
|
||||
# Add safety_stock_settings column
|
||||
op.add_column('tenant_settings',
|
||||
sa.Column('safety_stock_settings', postgresql.JSON(),
|
||||
nullable=False,
|
||||
server_default=str(default_settings["safety_stock_settings"]).replace("'", '"').replace("True", "true").replace("False", "false"))
|
||||
)
|
||||
|
||||
# Add moq_settings column
|
||||
op.add_column('tenant_settings',
|
||||
sa.Column('moq_settings', postgresql.JSON(),
|
||||
nullable=False,
|
||||
server_default=str(default_settings["moq_settings"]).replace("'", '"').replace("True", "true").replace("False", "false"))
|
||||
)
|
||||
|
||||
# Add supplier_selection_settings column
|
||||
op.add_column('tenant_settings',
|
||||
sa.Column('supplier_selection_settings', postgresql.JSON(),
|
||||
nullable=False,
|
||||
server_default=str(default_settings["supplier_selection_settings"]).replace("'", '"').replace("True", "true").replace("False", "false"))
|
||||
)
|
||||
|
||||
# Update the updated_at timestamp for all existing rows
|
||||
connection = op.get_bind()
|
||||
connection.execute(sa.text("UPDATE tenant_settings SET updated_at = now()"))
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""Remove the added settings columns from tenant_settings table"""
|
||||
op.drop_column('tenant_settings', 'supplier_selection_settings')
|
||||
op.drop_column('tenant_settings', 'moq_settings')
|
||||
op.drop_column('tenant_settings', 'safety_stock_settings')
|
||||
op.drop_column('tenant_settings', 'replenishment_settings')
|
||||
Reference in New Issue
Block a user