"""Account payee model.""" from typing import Protocol from abacus_common_logic.models.base import BaseModel, db from sqlalchemy.inspection import inspect class AccountPayee(BaseModel): """READ ONLY Account payee model.""" __tablename__ = 'account_payee' account_payee_id = db.Column(db.Integer, primary_key=True) account_id = db.Column(db.Integer, nullable=False, unique=True) payoneer_program_id = db.Column(db.Integer, nullable=True) payoneer_payee_id = db.Column(db.BigInteger, nullable=True) payoneer_payee_name = db.Column(db.String(180), nullable=True) payoneer_iframe_url = db.Column(db.String(180), nullable=True) payoneer_iframe_url_date = db.Column(db.Date, nullable=True) payoneer_session_id = db.Column(db.String(180), nullable=True) sap_vendor_id = db.Column(db.Integer, nullable=True) reference_payment_type_id = db.Column(db.SmallInteger, nullable=True) payment_description = db.Column(db.String(250), nullable=False) tax_form_info = db.relationship( 'TaxFormInfo', backref='account_payee', uselist=False, order_by='desc(TaxFormInfo.account_payee_tax_form_info_id)', ) account_tax_info = db.relationship( 'AccountTaxInfo', foreign_keys=[account_id], primaryjoin='AccountPayee.account_id == AccountTaxInfo.account_id', backref='account_payee', uselist=False, ) @property def entity_id_name(self): """Get payee entity id name.""" return inspect(self.__class__).primary_key[0].name @property def payee_entity_id(self): """Get payee entity id.""" return self.account_payee_id @property def payoneer_client_reference_id(self): """Get payoneer client reference id.""" return self.account_payee_id @classmethod def get_payees_by_ids(cls, account_payee_ids): """Get account_payee data by account_payee_ids""" return cls.query.filter(cls.account_payee_id.in_(account_payee_ids)).all() @classmethod def get_payee_by_id(cls, account_payee_id) -> 'AccountPayee': """Get account_payee data by account_payee_id""" return cls.query.filter(cls.account_payee_id == account_payee_id).first() @classmethod def get_payee_by_account_id(cls, account_id) -> 'AccountPayee': """Get account_payee data by account_id""" return cls.query.filter(cls.account_id == account_id).first() class PayeeProtocol(Protocol): """Type hints protocol for specified attributes.""" account_payee_id: int