"""Exchange rate model.""" from abacus_common_logic.connectors.database import db from abacus_common_logic.models.base import BaseModel from sqlalchemy import Index from sqlalchemy.orm import backref class ExchangeRate(BaseModel): """Exchange rate model.""" __tablename__ = 'exchange_rate' exchange_rate_id = db.Column(db.Integer, primary_key=True) statement_period_id = db.Column( db.Integer, db.ForeignKey('statement_period.statement_period_id'), nullable=False, ) statement_period = db.relationship( 'StatementPeriod', lazy='joined', backref=backref('exchange_rates', cascade='all, delete-orphan'), ) from_currency_code = db.Column(db.String(3), nullable=False) to_currency_code = db.Column(db.String(3), nullable=False) rate = db.Column(db.Numeric(30, 19), nullable=False) __table_args__ = ( Index( 'uq_statement_period_id_from_currency_code_to_currency_code', 'statement_period_id', 'from_currency_code', 'to_currency_code', unique=True, ), Index( 'ix_statement_period_id_from_currency_code_to_currency_code_rat', 'statement_period_id', 'from_currency_code', 'to_currency_code', 'rate', unique=False, ), )