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)```
Finally, to instruct OpenERP to really use the unaccent function, you have to
start the server specifying the ``--unaccent`` flag.
"""
import collections
import logging
import traceback
from zlib import crc32
import openerp.modules
from . import fields
from .. import SUPERUSER_ID
from ..models import MAGIC_COLUMNS, BaseModel
import openerp.tools as tools
# Domain operators.
NOT_OPERATOR = '!'
OR_OPERATOR = '|'
AND_OPERATOR = '&'
DOMAIN_OPERATORS = (NOT_OPERATOR, OR_OPERATOR, AND_OPERATOR)
# List of available term operators. It is also possible to use the '<>'
# operator, which is strictly the same as '!='; the later should be prefered
# for consistency. This list doesn't contain '<>' as it is simpified to '!='
# by the normalize_operator() function (so later part of the code deals with
# only one representation).
# Internals (i.e. not available to the user) 'inselect' and 'not inselect'
# operators are also used. In this case its right operand has the form (subselect, params).
TERM_OPERATORS = ('=', '!=', '<=', '<', '>', '>=', '=?', '=like', '=ilike',
                  'like', 'not like', 'ilike', 'not ilike', 'in', 'not in',
                  'child_of')
# A subset of the above operators, with a 'negative' semantic. When the
# expressions 'in NEGATIVE_TERM_OPERATORS' or 'not in NEGATIVE_TERM_OPERATORS' are used in the code
# below, this doesn't necessarily mean that any of those NEGATIVE_TERM_OPERATORS is