'Return a domain for the records that match the given condition.'

@api.model
def search_multi(self, name, model, operator, value):

    default_matches = False
    include_zero = False
    field = self.env[model]._fields[name]
    if (field.type == 'many2one'):
        comodel = field.comodel_name
        def makeref(value):
            return (value and ('%s,%s' % (comodel, value)))
        if (operator == '='):
            value = makeref(value)
            if (value is False):
                default_matches = True
        elif (operator in ('!=', '<=', '<', '>', '>=')):
            value = makeref(value)
        elif (operator in ('in', 'not    in')):
            value = map(makeref, value)
        elif (operator in ('=like', '=ilike', 'like', 'not    like', 'ilike', 'not    ilike')):
            target = self.env[comodel]
            target_names = target.name_search(value, operator=operator, limit=None)
            target_ids = map(itemgetter(0), target_names)
            (operator, value) = ('in', map(makeref, target_ids))
    elif (field.type in ('integer', 'float')):
        if ((value == 0) and (operator == '=')):
            operator = '!='
            include_zero = True
        elif ((value <= 0) and (operator == '>=')):
            operator = '<'
            include_zero = True
        elif ((value < 0) and (operator == '>')):
            operator = '<='
            include_zero = True
        elif ((value >= 0) and (operator == '<=')):
            operator = '>'
            include_zero = True
        elif ((value > 0) and (operator == '<')):
            operator = '>='
            include_zero = True
    domain = self._get_domain(name, model)
    if (domain is None):
        raise Exception()
    props = self.search((domain + [(TYPE2FIELD[field.type], operator, value)]))
    good_ids = []
    for prop in props:
        if prop.res_id:
            (res_model, res_id) = prop.res_id.split(',')
            good_ids.append(int(res_id))
        else:
            default_matches = True
    if include_zero:
        return [('id', 'not    in', good_ids)]
    elif default_matches:
        all_ids = []
        props = self.search((domain + [('res_id', '!=', False)]))
        for prop in props:
            (res_model, res_id) = prop.res_id.split(',')
            all_ids.append(int(res_id))
        bad_ids = list((set(all_ids) - set(good_ids)))
        return [('id', 'not    in', bad_ids)]
    else:
        return [('id', 'in', good_ids)]
