name_search方法的使用
2024-09-04 13:22:50
转自:http://blog.csdn.net/littlebo01/article/details/22075573
在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可能会不起作用
最新文章
- 深入浅出OOP(六): 理解C#的Enums
- Codeforces Round #337 Alphabet Permutations
- U盘启动
- Python核心编程--学习笔记--5--数字
- 11G RAC 简单命令
- 设计模式:Observer(观察者)—— Guava EventBus
- Light OJ 1021 - Painful Bases(状态压缩DP)
- System.InvalidOperationException: 无法加载协定为“ServiceReference1.XXXXXXXXXXXXXXXX”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。
- hdu 5422 Rikka with Graph(简单题)
- iOS 改变导航栏高度
- MVC无刷新查询,PagedList分页控件使用,导出Excel
- OC-不可变数组NSArray
- 给js动态创建的对象绑定事件
- Servlet,JSP 中的中文乱码问题以及解决方案
- select * 和 select 所有字段的区别
- 121、Data Binding(数据绑定)(转载)
- nginx屏蔽某段IP、某个国家的IP
- Redis中的简单动态字符串
- 将自己的域名解析跳转到博客主页(GitHub中的gitpage跳转)
- 如何确定一个NFS的mount是v3还是v4?