"""Accounting Period Report model.""" from abacus_common_logic.connectors.database import db from abacus_common_logic.models.base import BaseModel from sqlalchemy import Enum from sqlalchemy.orm import backref from royalties.constants import constants class AccountingPeriodReport(BaseModel): """Accounting Period Report model.""" __tablename__ = 'accounting_period_report' accounting_period_report_id = db.Column(db.Integer, primary_key=True) accounting_period_id = db.Column( db.Integer, db.ForeignKey('accounting_period.accounting_period_id'), nullable=False, ) report_type = db.Column( Enum(*constants.REPORT_TYPE, name='report_type', create_type=False), nullable=False, ) report_export_url = db.Column(db.String(180), nullable=False) accounting_period = db.relationship( 'AccountingPeriod', backref=backref('accounting_period_reports', lazy='joined'), lazy='joined', ) @classmethod def get_acc_period_reports(cls, period_id, report_type): """Get accounting period reports by period id and report type.""" return cls.query.filter( cls.accounting_period_id == period_id, cls.report_type == report_type )