diff options
| author | Raphael Collet <rco@odoo.com> | 2020-05-05 12:56:19 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-05-20 07:58:51 +0000 |
| commit | aed2134b6388258e907f8cb0dbd53857fb32d5c4 (patch) | |
| tree | ea5fb92f9917e88a1ad582f3a452149e0a32f822 /odoo/osv | |
| parent | 538f428787d15725383474a89e656c05a8c0b9fa (diff) | |
[REF] expression: search on translated fields
Use a LEFT JOIN on table `ir_translation` instead of a subquery, by
using the same implementation as the one used for ordering by a
translated field. In particular, this avoids having both the LEFT JOIN
and subquery when searching and sorting on a given translated field.
Diffstat (limited to 'odoo/osv')
| -rw-r--r-- | odoo/osv/expression.py | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index fc959c062ae..95edcecb023 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -966,40 +966,14 @@ class expression(object): 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: - # negate operator (fix lp:1071710) - sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '=' - inselect_operator = 'not inselect' + if sql_operator == 'in': + right = tuple(right) unaccent = self._unaccent if sql_operator.endswith('like') else lambda x: x + left = unaccent(model._generate_translated_field(alias, left, self.query)) instr = unaccent('%s') - - if sql_operator == 'in': - right = tuple(right) - - subselect = """WITH temp_irt_current (id, name) as ( - SELECT ct.id, coalesce(it.value,ct.{quote_left}) - FROM {current_table} ct - LEFT JOIN ir_translation it ON (it.name = %s and - it.lang = %s and - it.type = %s and - it.res_id = ct.id and - it.value != '') - ) - SELECT id FROM temp_irt_current WHERE {name} {operator} {right} order by name - """.format(current_table=model._table, quote_left=_quote(left), name=unaccent('name'), - operator=sql_operator, right=instr) - - params = ( - model._name + ',' + left, - get_lang(model.env).code, - 'model', - right, - ) - push(('id', inselect_operator, (subselect, params)), model, alias, internal=True) + push_result(f"{left} {sql_operator} {instr}", [right]) else: expr, params = self.__leaf_to_sql(leaf, model, alias) |
