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
sql_operator = {'=like': 'like', '=ilike': 'ilike'}.get(operator, operator)
            cast = '::text' if  sql_operator.endswith('like') else ''
            if left in model._columns:
                format = need_wildcard and '%s' or model._columns[left]._symbol_set[0]
                unaccent = self._unaccent if sql_operator.endswith('like') else lambda x: x
                column = '%s.%s' % (table_alias, _quote(left))
                query = '(%s %s %s)' % (unaccent(column + cast), sql_operator, unaccent(format))
            elif left in MAGIC_COLUMNS:
                    query = "(%s.\"%s\"%s %s %%s)" % (table_alias, left, cast, sql_operator)
                    params = right
            else:  # 
                raise ValueError("Invalid field %r in  %r" % (left, leaf))
            add_null = False
            if need_wildcard:
                if isinstance(right, str):
                    str_utf8 = right
                elif isinstance(right, unicode):
                    str_utf8 = right.encode('utf-8')
                else:
                    str_utf8 = str(right)
                params = '%%%s%%' % str_utf8
                add_null = not str_utf8
            elif left in model._columns:
                params = model._columns[left]._symbol_set[1](right)
            if add_null:
                query = '(%s OR %s."%s" IS NULL)' % (query, table_alias, left)
        if isinstance(params, basestring):
            params = [params]
        return query, params
    def to_sql(self):