'Search partner with a name and return its id, name and im_status.
Note : the user must be logged
:param name : the partner name to search
:param limit : the limit of result to return'

@api.model
def im_search(self, name, limit=20):

    if self.env['mail.channel'].check_access_rights('create', raise_exception=False):
        name = (('%' + name) + '%')
        excluded_partner_ids = [self.env.user.partner_id.id]
        self.env.cr.execute("\n                                                                SELECT\n                                                                                U.id    as    user_id,\n                                                                                P.id    as    id,\n                                                                                P.name    as    name,\n                                                                                CASE    WHEN    B.last_poll    IS    NULL    THEN    'offline'\n                                                                                                    WHEN    age(now()    AT    TIME    ZONE    'UTC',    B.last_poll)    >    interval    %s    THEN    'offline'\n                                                                                                    WHEN    age(now()    AT    TIME    ZONE    'UTC',    B.last_presence)    >    interval    %s    THEN    'away'\n                                                                                                    ELSE    'online'\n                                                                                END    as    im_status\n                                                                FROM    res_users    U\n                                                                                JOIN    res_partner    P    ON    P.id    =    U.partner_id\n                                                                                LEFT    JOIN    bus_presence    B    ON    B.user_id    =    U.id\n                                                                WHERE    P.name    ILIKE    %s\n                                                                                AND    P.id    NOT    IN    %s\n                                                                                AND    U.active    =    't'\n                                                                LIMIT    %s\n                                                ", (('%s    seconds' % DISCONNECTION_TIMER), ('%s    seconds' % AWAY_TIMER), name, tuple(excluded_partner_ids), limit))
        return self.env.cr.dictfetchall()
    else:
        return {}
