def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): self = self.sudo(name_get_uid or self.env.uid) if args is None: args = [] if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'): self.check_access_rights('read') where_query = self._where_calc(args) self._apply_ir_rules(where_query, 'read') from_clause, where_clause, where_clause_params = where_query.get_sql() from_str = from_clause if from_clause else 'res_partner' where_str = where_clause and (" WHERE %s AND " % where_clause) or ' WHERE ' # search on the name of the contacts and of its company search_name = name if operator in ('ilike', 'like'): search_name = '%%%s%%' % name if operator in ('=ilike', '=like'): operator = operator[1:] unaccent = get_unaccent_wrapper(self.env.cr) query = """SELECT res_partner.id FROM {from_str} {where} ({email} {operator} {percent} OR {display_name} {operator} {percent} OR {reference} {operator} {percent} OR {vat} {operator} {percent}) -- don't panic, trust postgres bitmap ORDER BY {display_name} {operator} {percent} desc, {display_name} """.format(from_str=from_str, where=where_str, operator=operator, email=unaccent('res_partner.email'), display_name=unaccent('res_partner.display_name'), reference=unaccent('res_partner.ref'), percent=unaccent('%s'), vat=unaccent('res_partner.vat'),) where_clause_params += [search_name]*3 # for email / display_name, reference where_clause_params += [re.sub('[^a-zA-Z0-9]+', '', search_name) or None] # for vat where_clause_params += [search_name] # for order by if limit: query += ' limit %s' where_clause_params.append(limit) self.env.cr.execute(query, where_clause_params) partner_ids = [row[0] for row in self.env.cr.fetchall()] if partner_ids: return models.lazy_name_get(self.browse(partner_ids)) else: return [] return super(Partner, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: domain = [ '|', ('name', operator, name), ('driver_id.name', operator, name) ] rec = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get(self.browse(rec).with_user(name_get_uid))
def _name_search(self, name, args=None, operator="ilike", limit=100, name_get_uid=None): args = args or [] if operator == "ilike" and not (name or "").strip(): domain = [] else: domain = [ "|", ("name", operator, name), ("state_id.code", operator, name) ] rec = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get(self.browse(rec).with_user(name_get_uid))
def name_search(self, name="", args=None, operator="ilike", limit=100): res = name_search.origin( self, name=name, args=args, operator=operator, limit=limit ) # For model with name_search_multi_lang, extend result multi_lang = _get_model_name_search_multi_lang(self, self._name) if multi_lang: context_lang = self._context.get("lang") installed_langs = self.env["res.lang"].get_installed() langs = [x[0] for x in installed_langs if x[0] != context_lang] for lang in langs: res = _extend_name_search_lang( self, lang, name, args, operator, res, limit ) domain = [("id", "in", [x[0] for x in res])] _ids = self._search(domain, limit=limit) res = models.lazy_name_get(self.browse(_ids)) return res
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None): if args is None: args = [] domain = args + [ '|', '|', ('name_seq', operator, name), ('contractor_id.name', operator, name), ('alias_work', operator, name) ] model_ids = self._search(domain, limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(model_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] equipment_ids = [] if name: equipment_ids = self._search([('name', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid) if not equipment_ids: equipment_ids = self._search([('name', operator, name)] + args, limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(equipment_ids).with_user(name_get_uid))
def location_name_search(self, name='', args=None, operator='ilike', limit=100): if args is None: args = [] records = self.browse() if len(name) == 2: records = self.search([('code', 'ilike', name)] + args, limit=limit) search_domain = [('name', operator, name)] if records: search_domain.append(('id', 'not in', records.ids)) records += self.search(search_domain + args, limit=limit) # the field 'display_name' calls name_get() to get its value return models.lazy_name_get(records)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if operator.startswith('!') or operator.startswith('not '): domain = [('name', operator, name), ('patient.name', operator, name)] else: domain = [ '|', '|', ('name', operator, name), ('patient.name', operator, name) ] rec = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get(self.browse(rec).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] domain = [] if name: domain = [ '|', ('bic', '=ilike', name + '%'), ('name', operator, name) ] if operator in expression.NEGATIVE_TERM_OPERATORS: domain = ['&'] + domain bank_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(bank_ids).with_user(name_get_uid))
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: domain = [ '|', '|', ('code', operator, name), ('name', operator, name), ('description', operator, name) ] record_ids = self._search(expression.AND([args, domain]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(record_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] domain = [] if name: domain = [ '|', ('code', '=ilike', name.split(' ')[0] + '%'), ('name', operator, name) ] if operator in expression.NEGATIVE_TERM_OPERATORS: domain = ['&', '!'] + domain[1:] account_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(account_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): """ search full name and barcode """ args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: domain = [ '|', '|', ('barcode', operator, name), ('complete_name', operator, name), ('code', operator, name) ] location_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(location_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if name: action_ids = self._search(expression.AND([[('action_id', operator, name)], args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(action_ids).with_user(name_get_uid)) return super(IrActionsTodo, self)._name_search(name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|' domain = [ connector, ('code', operator, name), ('name', operator, name) ] journal_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(journal_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: criteria_operator = [ '|' ] if operator not in expression.NEGATIVE_TERM_OPERATORS else [ '&', '!' ] domain = criteria_operator + [('asset_id', '=ilike', name + '%'), ('name', operator, name)] group_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(group_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): """ Returns a list of tuples containing id, name, as internally it is called {def name_get} result format: {[(id, name), (id, name), ...]} """ args = args or [] if operator == 'ilike' and not (name or '').strip(): domain = [] else: connector = '&' if operator in expression.NEGATIVE_TERM_OPERATORS else '|' domain = [ connector, ('description', operator, name), ('name', operator, name) ] tax_ids = self._search(expression.AND([domain, args]), limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(tax_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): if not args: args = [] if name: course_ids = self._search([('name', operator, name)] + args, limit=limit, access_rights_uid=name_get_uid) if not course_ids: course_ids = self._search([('course_name', operator, name)] + args, limit=limit, access_rights_uid=name_get_uid) else: course_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(course_ids).with_user(name_get_uid))
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): if name and operator == '=' and not args: # search on the name of the pricelist and its currency, opposite of name_get(), # Used by the magic context filter in the product search view. query_args = {'name': name, 'limit': limit, 'lang': get_lang(self.env).code} query = """SELECT p.id FROM (( SELECT pr.id, pr.name FROM product_pricelist pr JOIN res_currency cur ON (pr.currency_id = cur.id) WHERE pr.name || ' (' || cur.name || ')' = %(name)s ) UNION ( SELECT tr.res_id as id, tr.value as name FROM ir_translation tr JOIN product_pricelist pr ON ( pr.id = tr.res_id AND tr.type = 'model' AND tr.name = 'product.pricelist,name' AND tr.lang = %(lang)s ) JOIN res_currency cur ON (pr.currency_id = cur.id) WHERE tr.value || ' (' || cur.name || ')' = %(name)s ) ) p ORDER BY p.name""" if limit: query += " LIMIT %(limit)s" self._cr.execute(query, query_args) ids = [r[0] for r in self._cr.fetchall()] # regular search() to apply ACLs - may limit results below limit in some cases pricelist_ids = self._search([('id', 'in', ids)], limit=limit, access_rights_uid=name_get_uid) if pricelist_ids: return models.lazy_name_get(self.browse(pricelist_ids).with_user(name_get_uid)) return super(Pricelist, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): self = self.sudo(name_get_uid or self.env.uid) if args is None: args = [] if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'): self.check_access_rights('read') where_query = self._where_calc(args) self._apply_ir_rules(where_query, 'read') from_clause, where_clause, where_clause_params = where_query.get_sql( ) from_str = from_clause if from_clause else 'res_partner' where_str = where_clause and (" WHERE %s AND " % where_clause) or ' WHERE ' # search on the name of the contacts and of its company search_name = name if operator in ('ilike', 'like'): search_name = '%%%s%%' % name if operator in ('=ilike', '=like'): operator = operator[1:] unaccent = get_unaccent_wrapper(self.env.cr) query = """SELECT res_partner.id FROM {from_str} {where} ({email} {operator} {percent} OR {display_name} {operator} {percent} OR {reference} {operator} {percent} OR {vat} {operator} {percent}) -- don't panic, trust postgres bitmap ORDER BY {display_name} {operator} {percent} desc, {display_name} """.format( from_str=from_str, where=where_str, operator=operator, email=unaccent('res_partner.email'), display_name=unaccent('res_partner.display_name'), reference=unaccent('res_partner.ref'), percent=unaccent('%s'), vat=unaccent('res_partner.vat'), ) where_clause_params += [ search_name ] * 3 # for email / display_name, reference where_clause_params += [ re.sub('[^a-zA-Z0-9]+', '', search_name) or None ] # for vat where_clause_params += [search_name] # for order by if limit: query += ' limit %s' where_clause_params.append(limit) self.env.cr.execute(query, where_clause_params) partner_ids = [row[0] for row in self.env.cr.fetchall()] if partner_ids: return models.lazy_name_get(self.browse(partner_ids)) else: return [] return super(Partner, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): self = self.with_user(name_get_uid or self.env.uid) # as the implementation is in SQL, we force the recompute of fields if necessary self.recompute(['display_name']) self.flush() if args is None: args = [] order_by_rank = self.env.context.get('res_partner_search_mode') if (name or order_by_rank) and operator in ('=', 'ilike', '=ilike', 'like', '=like'): self.check_access_rights('read') where_query = self._where_calc(args) self._apply_ir_rules(where_query, 'read') from_clause, where_clause, where_clause_params = where_query.get_sql( ) from_str = from_clause if from_clause else 'res_partner' where_str = where_clause and (" WHERE %s AND " % where_clause) or ' WHERE ' # search on the name of the contacts and of its company search_name = name if operator in ('ilike', 'like'): search_name = '%%%s%%' % name if operator in ('=ilike', '=like'): operator = operator[1:] unaccent = get_unaccent_wrapper(self.env.cr) fields = self._get_name_search_order_by_fields() query = """SELECT res_partner.id FROM {from_str} {where} ({email} {operator} {percent} OR {display_name} {operator} {percent} OR {phone} {operator} {percent} OR {mobile} {operator} {percent} OR {reference} {operator} {percent} OR {vat} {operator} {percent}) -- don't panic, trust postgres bitmap ORDER BY {fields} {display_name} {operator} {percent} desc, {display_name} """.format( from_str=from_str, fields=fields, where=where_str, operator=operator, email=unaccent('res_partner.email'), phone=unaccent('res_partner.phone'), #add for search mobile=unaccent('res_partner.mobile'), #add for search display_name=unaccent('res_partner.display_name'), reference=unaccent('res_partner.ref'), percent=unaccent('%s'), vat=unaccent('res_partner.vat'), ) where_clause_params += [ search_name ] * 5 # for email / display_name, reference ,phone , mobile where_clause_params += [ re.sub('[^a-zA-Z0-9]+', '', search_name) or None ] # for vat where_clause_params += [search_name] # for order by if limit: query += ' limit %s' where_clause_params.append(limit) self.env.cr.execute(query, where_clause_params) partner_ids = [row[0] for row in self.env.cr.fetchall()] if partner_ids: return models.lazy_name_get(self.browse(partner_ids)) else: return [] return super(Partner, self)._name_search(name, args, operator=operator, limit=limit, name_get_uid=name_get_uid)
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): if not args: args = [] if name: positive_operators = ['=', 'ilike', '=ilike', 'like', '=like'] product_ids = [] if operator in positive_operators: product_ids = self._search([('default_code', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid) if not product_ids: product_ids = self._search([('barcode', '=', name)] + args, limit=limit, access_rights_uid=name_get_uid) if not product_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 # Performing a quick memory merge of ids in Python will give much better performance product_ids = self._search(args + [('default_code', operator, name)], limit=limit) if not limit or len(product_ids) < limit: # we may underrun the limit because of dupes in the results, that's fine limit2 = (limit - len(product_ids)) if limit else False product2_ids = self._search( args + [('name', operator, name), ('id', 'not in', product_ids)], limit=limit2, access_rights_uid=name_get_uid) product_ids.extend(product2_ids) elif not product_ids and operator in expression.NEGATIVE_TERM_OPERATORS: domain = expression.OR([ [ '&', ('default_code', operator, name), ('name', operator, name) ], [ '&', ('default_code', '=', False), ('name', operator, name) ], ]) domain = expression.AND([args, domain]) product_ids = self._search(domain, limit=limit, access_rights_uid=name_get_uid) if not product_ids and operator in positive_operators: ptrn = re.compile('(\[(.*?)\])') res = ptrn.search(name) if res: product_ids = self._search( [('default_code', '=', res.group(2))] + args, limit=limit, access_rights_uid=name_get_uid) # still no results, partner in context: search on supplier info as last hope to find something if not product_ids and self._context.get('partner_id'): suppliers_ids = self.env['product.supplierinfo']._search( [('name', '=', self._context.get('partner_id')), '|', ('product_code', operator, name), ('product_name', operator, name)], access_rights_uid=name_get_uid) if suppliers_ids: product_ids = self._search( [('product_tmpl_id.seller_ids', 'in', suppliers_ids)], limit=limit, access_rights_uid=name_get_uid) else: product_ids = self._search(args, limit=limit, access_rights_uid=name_get_uid) return models.lazy_name_get( self.browse(product_ids).with_user(name_get_uid))