Use of name_search Method

Source: Internet
Author: User

From: http://blog.csdn.net/littlebo01/article/details/22075573

In the many2one type, the name_search method is triggered when the page is pulled down. The parameters are not described here.,

Before optimization:

def name_search(self, cr, user, name, args=None, operator=‘ilike‘, context=None, limit=100):              if not args:                  args = []              if context.has_key(‘current_id‘):                  current_pid = context[‘current_id‘]                  cr.execute(‘select id from stock_picking_apply_move‘)                  ids_get = cr.fetchall()                  ids = []                  if not ids_get:                      pass                  else:                      for id in ids_get:                          ids.append(id[  0])                  moves_obj = self.pool.get(‘stock.picking.apply.move‘).browse(cr, user, ids, context=context)                  pro_ids = []                  for move in moves_obj:                      if move.jp_apply_picking_id.id==current_pid:                          pro_ids.append(move.product_id.id)                  return self.name_get(cr, user, pro_ids, context=context)              else:                  #super(jp_product_product,self).name_search(cr, user, name, args=args, operator=operator, context=context, limit=limit)                  tenant_id = context[‘tenant_id‘]                  if not tenant_id:                      raise except_osv(_(‘warning‘),_(‘必须选择租户‘))                  if context.has_key(‘tenant_id‘):                      cr.execute(‘select id from product_product where tenant_id = %s‘,(tenant_id,))                      ids_get = cr.fetchall()                      ids = []                      if not ids_get:                          return {}                      else:                          for id in ids_get:                              ids.append(id[  0])                          return self.name_get(cr, user, ids, context=context)                  else:                      raise except_osv(_(‘warning‘),_(‘必须选择租户‘))                               def name_get(self, cr, uid, ids, context=None):              """Get Product In Picking"""              if not len(ids):                  return []              res = [ (r[‘id‘], r[‘name‘] and r[‘name‘]                                            or r[‘name‘] )                      for r in self.read(cr, uid, ids, [‘name‘, ‘id‘],                                         context=context) ]              return res

After optimization:

def name_search(self, cr, user, name, args=None, operator=‘ilike‘, context=None, limit=100):          if context.has_key(‘current_id‘):              current_pid = context[‘current_id‘]                ids = []              apply_obj = self.pool.get(‘stock.picking.apply‘).browse(cr, user, current_pid, context=context)              for move_line in apply_obj.move_lines_apply:                  prod = move_line.product_id                  ids.append(move_line.product_id.id)                return self.name_get( cr, user, ids, context=None)            elif context.has_key(‘tenant_id‘):              if context[‘tenant_id‘] == False:                  raise except_osv(_(‘提示:‘),_(‘请选择租户‘))              args = [(‘tenant_id‘, ‘=‘, context[‘tenant_id‘])]            return super(jp_product_product,self).name_search(cr, user, name, args=args, operator=operator, context=context, limit=limit)

Are there any differences.

Note: If the name_search method is used, the domain in XML may not work.

Use of name_search Method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.