from openerp import SUPERUSER_ID
from openerp import tools
-from openerp.osv import osv, fields
+from openerp.osv import osv, fields, expression
from openerp.tools.translate import _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
import psycopg2
if not args:
args = []
if name:
- ids = self.search(cr, user, [('default_code','=',name)]+ args, limit=limit, context=context)
- if not ids:
- ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit, context=context)
- if not ids:
+ positive_operators = ['=', 'ilike', '=ilike', 'like', '=like']
+ ids = []
+ if operator in positive_operators:
+ ids = self.search(cr, user, [('default_code','=',name)]+ args, limit=limit, context=context)
+ if not ids:
+ ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit, context=context)
+ if not ids and operator not in expression.NEGATIVE_TERM_OPERATORS:
# Do not merge the 2 next lines into one single search, SQL search performance would be abysmal
# on a database with thousands of matching products, due to the huge merge+unique needed for the
# OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
limit2 = (limit - len(ids)) if limit else False
ids.update(self.search(cr, user, args + [('name', operator, name)], limit=limit2, context=context))
ids = list(ids)
- if not ids:
+ elif not ids and operator in expression.NEGATIVE_TERM_OPERATORS:
+ ids = self.search(cr, user, args + ['&', ('default_code', operator, name), ('name', operator, name)], limit=limit, context=context)
+ if not ids and operator in positive_operators:
ptrn = re.compile('(\[(.*?)\])')
res = ptrn.search(name)
if res: