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

@@ -1,8 +1,8 @@
"""unified initial procurement schema
"""unified initial procurement schema with all fields from all migrations
Revision ID: 001_unified_initial_schema
Revises:
Create Date: 2025-11-07
Create Date: 2025-11-27 12:00:00.000000+00:00
Complete procurement service schema including:
- Procurement plans and requirements
@@ -13,6 +13,7 @@ Complete procurement service schema including:
- Inventory projections
- Supplier allocations and selection history
- Audit logs
- Internal transfer fields
"""
from typing import Sequence, Union
@@ -207,7 +208,7 @@ def upgrade() -> None:
# PURCHASE ORDER TABLES
# ========================================================================
# Create purchase_orders table (with reasoning_data for i18n)
# Create purchase_orders table (with reasoning_data for i18n and internal transfer fields)
op.create_table('purchase_orders',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('tenant_id', postgresql.UUID(as_uuid=True), nullable=False),
@@ -245,6 +246,11 @@ def upgrade() -> None:
sa.Column('terms_and_conditions', sa.Text(), nullable=True),
# JTBD Dashboard: Structured reasoning for i18n support
sa.Column('reasoning_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
# Internal transfer fields
sa.Column('is_internal', sa.Boolean(), nullable=False, server_default='false'),
sa.Column('source_tenant_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('destination_tenant_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('transfer_type', sa.String(length=50), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), onupdate=sa.text('now()'), nullable=False),
sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=False),
@@ -262,6 +268,11 @@ def upgrade() -> None:
op.create_index('ix_purchase_orders_tenant_plan', 'purchase_orders', ['tenant_id', 'procurement_plan_id'], unique=False)
op.create_index('ix_purchase_orders_order_date', 'purchase_orders', ['order_date'], unique=False)
op.create_index('ix_purchase_orders_delivery_date', 'purchase_orders', ['required_delivery_date'], unique=False)
# Internal transfer indexes
op.create_index('ix_purchase_orders_is_internal', 'purchase_orders', ['is_internal'])
op.create_index('ix_purchase_orders_source_tenant', 'purchase_orders', ['source_tenant_id'])
op.create_index('ix_purchase_orders_destination_tenant', 'purchase_orders', ['destination_tenant_id'])
op.create_index('ix_po_internal_transfers', 'purchase_orders', ['tenant_id', 'is_internal', 'source_tenant_id'])
# Create purchase_order_items table (with supplier_price_list_id)
op.create_table('purchase_order_items',
@@ -328,7 +339,7 @@ def upgrade() -> None:
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), onupdate=sa.text('now()'), nullable=False),
sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['purchase_order_id'], ['purchase_orders.id'], ondelete='CASCADE'),
# Note: supplier_id references suppliers service - no FK constraint in microservices
# ... Note: supplier_id references suppliers service - no FK constraint in microservices
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_deliveries_delivery_number'), 'deliveries', ['delivery_number'], unique=True)
@@ -603,4 +614,4 @@ def downgrade() -> None:
# Drop enum types
op.execute("DROP TYPE IF EXISTS purchaseorderstatus")
op.execute("DROP TYPE IF EXISTS deliverystatus")
op.execute("DROP TYPE IF EXISTS invoicestatus")
op.execute("DROP TYPE IF EXISTS invoicestatus")