Impacted versions:
8.0 and so on

Steps to reproduce:
create a many2many field in product.product such as:
`'company_ids':fields.many2many('res.company','res_company_product_rel','partner_id','company_ids',string=u'multi company''),`
and add a ir.rule for product.product with  domain such as
`['|',('company_id','=',False),('company_ids','in',[c.id for c in user.company_ids])]`
and import 10 thousand product.
then login with normal user(not super) and open the product.produt list view
it taks several minus to open

Current behavior:
when I search product.product
all product id have been hard coded in the sql 
lead to low performance.

Expected behavior:
not hard code produt id

Video/Screenshot link (optional):
in the sql below 10 thousand product id have been hard code in the position %s
AND ("product_product__product_tmpl_id"."company_id" IS NULL   OR  ("product_product"."id" in (%s)))

openerp/osv/expression.py
if isinstance(right, basestring) or \
                            right and isinstance(right, (tuple, list)) and all(isinstance(item, basestring) for item in right):
                        push(create_substitution_leaf(leaf, _get_expression(comodel, cr, uid, left, right, operator, context=context), model))
                    else:
                        # 
                        push_(leaf)
            # 
            # 
            # 
            #    
            # 
            # 
            else:
                if column._type == 'datetime' and right and len(right) == 10:
                    if operator in ('>', '<='):
                        right += ' 23:59:59'
                    else:
                        right += ' 00:00:00'
                    push(create_substitution_leaf(leaf, (left, operator, right), model))
                elif column.translate and right:
                    need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike')
                    sql_operator = {'=like': 'like', '=ilike': 'ilike'}.get(operator, operator)
                    if need_wildcard:
                        right = '%%%s%%' % right
                    inselect_operator = 'inselect'
                    if sql_operator in NEGATIVE_TERM_OPERATORS:
                        # 
                        sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '='
                        inselect_operator = 'not inselect'
                    unaccent = self._unaccent if sql_operator.endswith('like') else lambda x: x