Tries to pay pending account invoices (starting from the oldest) with available funds.
    :param account_id: the account on which to perform the operation
    :return: The ids of the invoices that were paid (possibly empty list).

def assign_funds_to_account_pending_invoices(account_id: str) -> Sequence[str]:
    """
    Tries to pay pending account invoices (starting from the oldest) with available funds.
    :param account_id: the account on which to perform the operation
    :return: The ids of the invoices that were paid (possibly empty list).
    """
    logger.info('assign-funds-to-pending-invoices', account_id=str(account_id))

    paid_invoice_ids = []
    for invoice in Invoice.objects.filter(status=Invoice.PENDING, account_id=account_id).order_by('due_date'):
        invoice_was_paid = assign_funds_to_invoice(invoice.pk)
        if invoice_was_paid:
            paid_invoice_ids.append(invoice.id)
        else:
            break  # Bail even though there may be funds in another currency to pay more recent invoices.
    logger.info('assign-funds-to-pending-invoices.end', account_id=str(account_id),
                paid_invoice_count=len(paid_invoice_ids))
    return paid_invoice_ids