"""Payee related logic.""" from collaborator.models.ows import ows_abacus_account, ows_abacus_state def is_account_payment_eligible(vendor_id: int) -> bool: """Check if account is payment eligible. Args: vendor_id (int): ID of the vendor. Returns: bool: True if payment eligible, False otherwise. """ account_payee = ows_abacus_account.get_account_payee(vendor_id) if not account_payee.get("items"): return False account_payee_id = ( account_payee.get("items", [{}])[0].get("data", {}).get("account_payee_id") ) abacus_states = ows_abacus_state.get_abacus_states(account_payee_id) payment_eligibility_status = _get_abacus_state_status( abacus_states, "payment_eligibility" ) tax_eligibility_status = _get_abacus_state_status(abacus_states, "tax_eligibility") banking_details_review_status = _get_abacus_state_status( abacus_states, "banking_details_review" ) ok_statuses = ["approved", "complete"] return ( payment_eligibility_status in ok_statuses and tax_eligibility_status in ok_statuses and banking_details_review_status in ok_statuses ) def _get_abacus_state_status(states: list[dict], action_name: str) -> str | None: for state in states: if state.get("action_name") == action_name: return state.get("action_status") return None