"""signing_entity_sap_profit_center model.""" from abacus_common_logic.connectors.database import db from abacus_common_logic.models import BaseSoftDeleteModel class SigningEntitySapProfitCenter(BaseSoftDeleteModel): """Junction authorizing which SAP profit centers a signing entity may route revenue through.""" __tablename__ = 'signing_entity_sap_profit_center' signing_entity_sap_profit_center_id = db.Column(db.Integer, primary_key=True) reference_signing_entity_id = db.Column( db.Integer, db.ForeignKey('reference_signing_entity.reference_signing_entity_id'), nullable=False, ) reference_sap_profit_center_id = db.Column( db.Integer, db.ForeignKey('reference_sap_profit_center.reference_sap_profit_center_id'), nullable=False, ) reference_signing_entity = db.relationship('ReferenceSigningEntity') reference_sap_profit_center = db.relationship('ReferenceSapProfitCenter') @classmethod def get_by_profit_center_and_signing_entities( cls, sap_profit_center_id: int, signing_entity_ids: list, ): """Fetch all junction rows matching the specified profit center and signing entities. Args: sap_profit_center_id (int): ID of the SAP profit center. signing_entity_ids (list): List of signing entity IDs to filter by. Returns: list: A list of matching junction model instances. """ return cls.query.filter( cls.reference_sap_profit_center_id == sap_profit_center_id, cls.reference_signing_entity_id.in_(signing_entity_ids), ).all()