Files
orion/alembic/versions/i7d8e9f0a1b2_add_vendor_subscriptions.py
Samir Boulahtit 6232bb47f6 feat: add invoicing system and subscription tier enforcement
Phase 1 OMS implementation:

Invoicing:
- Add Invoice and VendorInvoiceSettings database models
- Full EU VAT support (27 countries, OSS, B2B reverse charge)
- Invoice PDF generation with WeasyPrint + Jinja2 templates
- Vendor invoice API endpoints for settings, creation, PDF download

Subscription Tiers:
- Add VendorSubscription model with 4 tiers (Essential/Professional/Business/Enterprise)
- Tier limit enforcement for orders, products, team members
- Feature gating based on subscription tier
- Automatic trial subscription creation for new vendors
- Integrate limit checks into order creation (direct and Letzshop sync)

Marketing:
- Update pricing documentation with 4-tier structure
- Revise back-office positioning strategy
- Update homepage with Veeqo-inspired Letzshop-focused messaging

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-24 18:15:27 +01:00

149 lines
4.8 KiB
Python

"""Add vendor subscriptions table
Revision ID: i7d8e9f0a1b2
Revises: h6c7d8e9f0a1
Create Date: 2025-12-24
This migration adds:
- vendor_subscriptions: Per-vendor subscription tracking with tier limits
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "i7d8e9f0a1b2"
down_revision: Union[str, None] = "h6c7d8e9f0a1"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Create vendor_subscriptions table
op.create_table(
"vendor_subscriptions",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("vendor_id", sa.Integer(), nullable=False),
# Tier and status
sa.Column(
"tier", sa.String(length=20), server_default="essential", nullable=False
),
sa.Column(
"status", sa.String(length=20), server_default="trial", nullable=False
),
# Billing period
sa.Column("period_start", sa.DateTime(timezone=True), nullable=False),
sa.Column("period_end", sa.DateTime(timezone=True), nullable=False),
sa.Column("is_annual", sa.Boolean(), server_default="0", nullable=False),
# Trial
sa.Column("trial_ends_at", sa.DateTime(timezone=True), nullable=True),
# Usage counters
sa.Column("orders_this_period", sa.Integer(), server_default="0", nullable=False),
sa.Column("orders_limit_reached_at", sa.DateTime(timezone=True), nullable=True),
# Custom overrides
sa.Column("custom_orders_limit", sa.Integer(), nullable=True),
sa.Column("custom_products_limit", sa.Integer(), nullable=True),
sa.Column("custom_team_limit", sa.Integer(), nullable=True),
# Payment (future Stripe integration)
sa.Column("stripe_customer_id", sa.String(length=100), nullable=True),
sa.Column("stripe_subscription_id", sa.String(length=100), nullable=True),
# Cancellation
sa.Column("cancelled_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("cancellation_reason", sa.Text(), nullable=True),
# Timestamps
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("(CURRENT_TIMESTAMP)"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("(CURRENT_TIMESTAMP)"),
nullable=False,
),
sa.ForeignKeyConstraint(
["vendor_id"],
["vendors.id"],
),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("vendor_id"),
)
op.create_index(
op.f("ix_vendor_subscriptions_id"),
"vendor_subscriptions",
["id"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_vendor_id"),
"vendor_subscriptions",
["vendor_id"],
unique=True,
)
op.create_index(
op.f("ix_vendor_subscriptions_tier"),
"vendor_subscriptions",
["tier"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_status"),
"vendor_subscriptions",
["status"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_stripe_customer_id"),
"vendor_subscriptions",
["stripe_customer_id"],
unique=False,
)
op.create_index(
op.f("ix_vendor_subscriptions_stripe_subscription_id"),
"vendor_subscriptions",
["stripe_subscription_id"],
unique=False,
)
op.create_index(
"idx_subscription_vendor_status",
"vendor_subscriptions",
["vendor_id", "status"],
unique=False,
)
op.create_index(
"idx_subscription_period",
"vendor_subscriptions",
["period_start", "period_end"],
unique=False,
)
def downgrade() -> None:
op.drop_index("idx_subscription_period", table_name="vendor_subscriptions")
op.drop_index("idx_subscription_vendor_status", table_name="vendor_subscriptions")
op.drop_index(
op.f("ix_vendor_subscriptions_stripe_subscription_id"),
table_name="vendor_subscriptions",
)
op.drop_index(
op.f("ix_vendor_subscriptions_stripe_customer_id"),
table_name="vendor_subscriptions",
)
op.drop_index(
op.f("ix_vendor_subscriptions_status"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_tier"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_vendor_id"), table_name="vendor_subscriptions"
)
op.drop_index(
op.f("ix_vendor_subscriptions_id"), table_name="vendor_subscriptions"
)
op.drop_table("vendor_subscriptions")