Files
delphi-database/app/models/pensions.py
2025-08-08 15:55:15 -05:00

158 lines
5.5 KiB
Python

"""
Pension calculation models based on legacy PENSION.SC analysis
"""
from sqlalchemy import Column, Integer, String, Date, Text, Float, ForeignKey
from sqlalchemy.orm import relationship
from app.models.base import BaseModel
class Pension(BaseModel):
"""
Pension calculation data
Corresponds to PENSIONS table in legacy system
"""
__tablename__ = "pensions"
id = Column(Integer, primary_key=True, autoincrement=True)
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
version = Column(String(10), default="01") # Version number
plan_id = Column(String(45)) # Plan identifier
plan_name = Column(String(200)) # Name of pension plan
# Participant information
title = Column(String(10)) # Mr., Mrs., Ms., etc.
first = Column(String(50)) # First name
last = Column(String(100)) # Last name
birth = Column(Date) # Date of birth
race = Column(String(1)) # Race code
sex = Column(String(1)) # M/F
# Pension calculation data
info = Column(Text) # Additional pension information
valu = Column(Float, default=0.0) # Pension valuation
accrued = Column(Float, default=0.0) # Accrued benefit
vested_per = Column(Float, default=0.0) # Vested percentage
start_age = Column(Integer) # Starting age for benefits
# Cost of living and withdrawal details
cola = Column(Float, default=0.0) # Cost of living adjustment
max_cola = Column(Float, default=0.0) # Maximum COLA
withdrawal = Column(String(45)) # Withdrawal method
pre_dr = Column(Float, default=0.0) # Pre-retirement discount rate
post_dr = Column(Float, default=0.0) # Post-retirement discount rate
tax_rate = Column(Float, default=0.0) # Tax rate
# Relationships
file = relationship("File", back_populates="pensions")
def __repr__(self):
return f"<Pension(file_no='{self.file_no}', plan_name='{self.plan_name}')>"
class PensionSchedule(BaseModel):
"""
Pension payment schedules
Corresponds to SCHEDULE table in legacy system
"""
__tablename__ = "pension_schedules"
id = Column(Integer, primary_key=True, autoincrement=True)
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
version = Column(String(10), default="01")
# Schedule details
start_date = Column(Date) # Start date for payments
end_date = Column(Date) # End date for payments
payment_amount = Column(Float, default=0.0) # Payment amount
frequency = Column(String(20)) # Monthly, quarterly, etc.
# Relationships
file = relationship("File", back_populates="pension_schedules")
class MarriageHistory(BaseModel):
"""
Marriage/divorce history for pension calculations
Corresponds to MARRIAGE table in legacy system
"""
__tablename__ = "marriage_history"
id = Column(Integer, primary_key=True, autoincrement=True)
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
# Marriage details
marriage_date = Column(Date) # Date of marriage
divorce_date = Column(Date) # Date of divorce/separation
spouse_name = Column(String(100)) # Spouse name
notes = Column(Text) # Additional notes
# Relationships
file = relationship("File", back_populates="marriage_history")
class DeathBenefit(BaseModel):
"""
Death benefit information
Corresponds to DEATH table in legacy system
"""
__tablename__ = "death_benefits"
id = Column(Integer, primary_key=True, autoincrement=True)
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
# Death benefit details
beneficiary_name = Column(String(100)) # Beneficiary name
benefit_amount = Column(Float, default=0.0) # Benefit amount
benefit_type = Column(String(45)) # Type of death benefit
notes = Column(Text) # Additional notes
# Relationships
file = relationship("File", back_populates="death_benefits")
class SeparationAgreement(BaseModel):
"""
Separation agreement details
Corresponds to SEPARATE table in legacy system
"""
__tablename__ = "separation_agreements"
id = Column(Integer, primary_key=True, autoincrement=True)
file_no = Column(String(45), ForeignKey("files.file_no"), nullable=False)
# Agreement details
agreement_date = Column(Date) # Date of agreement
terms = Column(Text) # Terms of separation
notes = Column(Text) # Additional notes
# Relationships
file = relationship("File", back_populates="separation_agreements")
class LifeTable(BaseModel):
"""
Life expectancy tables for actuarial calculations
Corresponds to LIFETABL table in legacy system
"""
__tablename__ = "life_tables"
id = Column(Integer, primary_key=True, autoincrement=True)
age = Column(Integer, nullable=False) # Age
male_expectancy = Column(Float) # Male life expectancy
female_expectancy = Column(Float) # Female life expectancy
table_year = Column(Integer) # Year of table (e.g., 2023)
table_type = Column(String(45)) # Type of table
class NumberTable(BaseModel):
"""
Numerical tables for calculations
Corresponds to NUMBERAL table in legacy system
"""
__tablename__ = "number_tables"
id = Column(Integer, primary_key=True, autoincrement=True)
table_type = Column(String(45), nullable=False) # Type of table
key_value = Column(String(45), nullable=False) # Key identifier
numeric_value = Column(Float) # Numeric value
description = Column(Text) # Description