Files
WealthySmart/backend/alembic/versions/961802a2f50d_installment_plans_tasa_cero.py
Carlos Escalante 088062f757 Tasa Cero: InstallmentPlan model, cuota service, migration
BAC zero-interest financing: an anchor purchase splits into N monthly
cuota transactions (truncate-to-0.10 rule, last cuota absorbs rounding;
one cuota per 18th-cut billing cycle on the 19th). Pinned against real
Financiamientos data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 16:13:00 -06:00

56 lines
2.5 KiB
Python

"""installment plans (tasa cero)
Revision ID: 961802a2f50d
Revises: 7884505b16b3
Create Date: 2026-07-03 16:00:55.026771
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '961802a2f50d'
down_revision: Union[str, Sequence[str], None] = '7884505b16b3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('installmentplan',
sa.Column('num_installments', sa.Integer(), nullable=False),
sa.Column('first_installment_date', sa.DateTime(), nullable=False),
sa.Column('total_amount', sa.Numeric(precision=15, scale=2), nullable=False),
sa.Column('installment_amount', sa.Numeric(precision=15, scale=2), nullable=False),
# Reuse the existing 'currency' enum type — do NOT re-create it.
sa.Column('currency', postgresql.ENUM('CRC', 'USD', 'EUR', 'BTC', 'XMR', name='currency', create_type=False), nullable=False),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('anchor_transaction_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['anchor_transaction_id'], ['transaction.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_installmentplan_anchor_transaction_id'), 'installmentplan', ['anchor_transaction_id'], unique=True)
op.add_column('transaction', sa.Column('installment_plan_id', sa.Integer(), nullable=True))
op.add_column('transaction', sa.Column('is_installment_anchor', sa.Boolean(), server_default='false', nullable=False))
op.create_index(op.f('ix_transaction_installment_plan_id'), 'transaction', ['installment_plan_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_transaction_installment_plan_id'), table_name='transaction')
op.drop_column('transaction', 'is_installment_anchor')
op.drop_column('transaction', 'installment_plan_id')
op.drop_index(op.f('ix_installmentplan_anchor_transaction_id'), table_name='installmentplan')
op.drop_table('installmentplan')
# ### end Alembic commands ###