"""Account Payment Term model.""" from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import Enum from sqlalchemy import Integer from sqlalchemy import Numeric from sqlalchemy import String from sqlalchemy.engine import Row from moneyhub.constants.constants import PaymentSchedule from moneyhub.models.mysql_base import BaseModel class AccountPaymentTerm(BaseModel): """Account Payment Term model.""" __tablename__ = 'account_payment_term' account_payment_term_id = Column(Integer, primary_key=True, nullable=False) account_id = Column(Integer, primary_key=False, nullable=False) currency_code = Column(String(3), nullable=True) payment_minimum = Column(Numeric(20, 2), nullable=True) payment_entity_id = Column(Integer, primary_key=False, nullable=True) agreement_type_id = Column(Integer, nullable=True) payment_schedule = Column( Enum( *PaymentSchedule, name='payment_schedule', create_type=False ), nullable=True) created_by = Column(String(255), nullable=True) created_at = Column(DateTime, nullable=True) last_modified_by = Column(String(255), nullable=True) last_modified = Column(DateTime, nullable=True) @classmethod def get_by_account_id(cls, account_id: int) -> Row: """GET account payment term for a specified account ID. Args: account_id (int): the id of an account Returns: Row: Account payment term row """ return cls.query.filter(cls.account_id == account_id).first()