OpenERP name_search方法的使用


             在many2one类型中,页面下拉时会首先触发name_search方法,参数这里就不解释了


             优化前:

                     

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



             优化后:


                       

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)

有没有发现,差异很大呢。

注意:使用了name_search方法,在xml中加的domain可能会不起作用


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值