"""AccountingRun Model. It is a READ ONLY model for accessing data. The real business logic lives in the ows-royalties repository. """ from abacus_common_logic.connectors.database import db from sqlalchemy import select, text from sqlalchemy.sql import literal_column, table class AccountingRun: """AccountingRun Model.""" @classmethod def get_accounting_runs_by_accounting_period_id( cls, accounting_period_id: int, ): """Get accounting runs by accounting_period_id. Args: accounting_period_id (int): id of the accounting period. Returns: a list of accounting runs. """ accounting_run_query = ( select( [ literal_column('ar.accounting_period_id').label( 'accounting_period_id' ), literal_column('ar.run_controller_id').label('run_controller_id'), literal_column('ar.run_status').label('accounting_run_status'), ] ) .where(text('ar.accounting_period_id = :accounting_period_id')) .select_from(table('accounting_run').alias('ar')) ) return db.session.execute( accounting_run_query, {'accounting_period_id': accounting_period_id} ).fetchall()