From 0b593ada11f6222803949705c508a5616c3e6a3e Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Tue, 24 Jun 2014 17:42:48 +0530 Subject: [PATCH] Server Translation: Fixed the issue search on translated field do not return true result, search on tranlsated field fails due to expression parsing which fetches ids from ir_translation as well as working table and UNION of this makes search fruitless, also search fails for in language other then english when you enter part of a string for the field to search. --- openerp/osv/expression.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 68ad4c2..18c8230 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -1037,34 +1037,30 @@ class expression(object): unaccent = self._unaccent if sql_operator.endswith('like') else lambda x: x - trans_left = unaccent('value') - quote_left = unaccent(_quote(left)) instr = unaccent('%s') if sql_operator == 'in': # params will be flatten by to_sql() => expand the placeholders instr = '(%s)' % ', '.join(['%s'] * len(right)) - subselect = """(SELECT res_id - FROM ir_translation - WHERE name = %s - AND lang = %s - AND type = %s - AND {trans_left} {operator} {right} - ) UNION ( - SELECT id - FROM "{table}" - WHERE {left} {operator} {right} - ) - """.format(trans_left=trans_left, operator=sql_operator, - right=instr, table=working_model._table, left=quote_left) + 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=working_model._table, quote_left=_quote(left), name=unaccent('name'), + operator=sql_operator, right=instr) params = ( working_model._name + ',' + left, context.get('lang') or 'en_US', 'model', right, - right, ) push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), working_model)) -- 1.7.10.4