Impacted versions:

8, 9, 10, master

Steps to reproduce:

Run `odoo shell --log-level=debug_sql` on a database where accounting is installed with demo data.

```
>>> AML = env['account.move.line']
>>> AML.search([('tax_ids.amount', '=', 15)])
```

You get the following trace of 4 sql statements:

The first one is ok:
```sql
SELECT "account_tax".id FROM "account_tax" WHERE (("account_tax"."active" = %s)  AND  ("account_tax"."amount" = %s)) ORDER BY "account_tax"."sequence"  
```

The second one can be improved and is discussed in https://github.com/odoo/odoo/pull/16066, it's not the point of this issue.
```sql
SELECT "account_move_line_id" FROM "account_move_line_account_tax_rel" WHERE "account_tax_id" IN %s
```

Then it does the same query twice with apparently no good reason (at least none I understand).
```sql
SELECT "account_move_line".id FROM "account_move_line" WHERE ("account_move_line"."id" in (%s)) ORDER BY "account_move_line"."date" DESC,"account_move_line"."id" DESC 
SELECT "account_move_line".id FROM "account_move_line" WHERE ("account_move_line"."id" in (%s)) ORDER BY "account_move_line"."date" DESC,"account_move_line"."id" DESC 
```

The problem has its source [here](https://github.com/odoo/odoo/blob/b8ce0db8e105ed3c9ab4aefe8bce5028764694f4/odoo/osv/expression.py#L879): at first glance I'd say lines 879 and 880 could be replaced with

```leaf.leaf = (path[0], 'in', right_ids)```
openerp/osv/expression.py
:var list path: left operand seen as a sequence of field names
                    ("foo.bar" -> ["foo", "bar"])
                :var obj model: model object, model containing the field
                    (the name provided in the left operand)
                :var obj field: the field corresponding to `path[0]`
                :var obj column: the column corresponding to `path[0]`
                :var obj comodel: relational model of field (field.comodel)
                    (res_partner.bank_ids -> res.partner.bank)
        """
        def to_ids(value, comodel, context=None, limit=None):
            """ Normalize a single id or name, or a list of those, into a list of ids
                :param {int,long,basestring,list,tuple} value:
                    if int, long -> return [value]
                    if basestring, convert it into a list of basestrings, then
                    if list of basestring ->
                        perform a name_search on comodel for each name
                        return the list of related ids
            """
            names = []
            if isinstance(value, basestring):
                names = [value]
            elif value and isinstance(value, (tuple, list)) and all(isinstance(item, basestring) for item in value):
                names = value
            elif isinstance(value, (int, long)):
                return [value]
            if names:
                name_get_list = [name_get[0] for name in names for name_get in comodel.name_search(cr, uid, name, [], 'ilike', context=context, limit=limit)]
                return list(set(name_get_list))
            return list(value)
        def child_of_domain(left, ids, left_model, parent=None, prefix='', context=None):