"""LedgerCorrection model.""" from abacus_common_logic.connectors.database import db from abacus_common_logic.models.base import BaseModel from sqlalchemy import Enum from ledger.constants.constants import CORRECTION_TYPES class LedgerCorrection(BaseModel): """Ledger Correction model.""" __tablename__ = 'ledger_correction' ledger_correction_id = db.Column(db.Integer, primary_key=True) abacus_event_id = db.Column(db.Integer, nullable=False) worksheet_correction_id = db.Column(db.Integer, nullable=False) account_id = db.Column(db.Integer, nullable=False) contract_id = db.Column(db.Integer, nullable=True) statement_period_id = db.Column(db.Integer, nullable=False) correction_statement_period_id = db.Column(db.Integer, nullable=False) correction_type = db.Column( Enum(*CORRECTION_TYPES, name='correction_type', create_type=False), default=CORRECTION_TYPES.ROYALTY_REVERSAL, nullable=False, ) currency_code = db.Column(db.String(3), nullable=False) gross_revenue = db.Column(db.Numeric(20, 2), nullable=False) distribution_fee = db.Column(db.Numeric(20, 2), nullable=False) mechanical_deduction_total = db.Column(db.Numeric(20, 2), nullable=True) mechanical_deduction_admin_fee_total = db.Column(db.Numeric(20, 2), nullable=True) net_revenue = db.Column(db.Numeric(20, 2), nullable=False) note = db.Column(db.Text, nullable=True) @classmethod def get_by_worksheet_correction_ids(cls, worksheet_correction_ids: list) -> list: """Get ledger_correction records by worksheet_correction_id's. Args: worksheet_correction_ids (list): a list of worksheet_correction_id's Returns: A list of ledger_correction records """ return cls.query.filter( cls.worksheet_correction_id.in_(worksheet_correction_ids) ).all()