name_search方法的使用
转自: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可能会不起作用
name_search方法的使用的更多相关文章
- javaSE27天复习总结
JAVA学习总结 2 第一天 2 1:计算机概述(了解) 2 (1)计算机 2 (2)计算机硬件 2 (3)计算机软件 2 (4)软件开发(理解) 2 (5) ...
- OpenERP ORM 对象方法列表
OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetime, binary:复杂类型:select ...
- openerp经典收藏 对象的预定义方法(转载)
对象的预定义方法 原文:http://shine-it.net/index.php/topic,2159.15.html 每个OpenERP的对象都有一些预定义方法,这些方法定义在基类osv.osv中 ...
- Odoo模型的内置方法(可按需重写)
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826222.html ==========模型层面========== 一:_table_exist 检查 ...
- mapreduce多文件输出的两方法
mapreduce多文件输出的两方法 package duogemap; import java.io.IOException; import org.apache.hadoop.conf ...
- 【.net 深呼吸】细说CodeDom(6):方法参数
本文老周就给大伙伴们介绍一下方法参数代码的生成. 在开始之前,先补充一下上一篇烂文的内容.在上一篇文章中,老周检讨了 MemberAttributes 枚举的用法,老周此前误以为该枚举不能进行按位操作 ...
- IE6、7下html标签间存在空白符,导致渲染后占用多余空白位置的原因及解决方法
直接上图:原因:该div包含的内容是靠后台进行print操作,输出的.如果没有输出任何内容,浏览器会默认给该空白区域添加空白符.在IE6.7下,浏览器解析渲染时,会认为空白符也是占位置的,默认其具有字 ...
- 多线程爬坑之路-Thread和Runable源码解析之基本方法的运用实例
前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...
- [C#] C# 基础回顾 - 匿名方法
C# 基础回顾 - 匿名方法 目录 简介 匿名方法的参数使用范围 委托示例 简介 在 C# 2.0 之前的版本中,我们创建委托的唯一形式 -- 命名方法. 而 C# 2.0 -- 引进了匿名方法,在 ...
随机推荐
- 32、Flask实战第32天:优化json数据的返回
接着上节,我们通过jsonify返回json数据非常方便 ... return jsonify({"code": 400, "message": message ...
- Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)
Pipeline as Code是2.0的精髓所在,是帮助Jenkins实现CI(Continuous Integration)到CD(Continuous Delivery)华丽转身的关键推手.所谓 ...
- BZOJ 3669 [Noi2014]魔法森林(贪心+LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3669 [题目大意] 给出一张图,每条边上有两个值ai和bi,现在需要求出一条1到N的路 ...
- java面试笔试总结(一)--亲生经历的面试题
说明:本文只是自己的一些心得体会,答案也是自己写的,正确与否,还需考证 java笔试题 1java笔试题1 启动3个线程打印递增的数字, 线程1先打印1,2,3,4,5, 然后是线程2打印6,7 ...
- 忘记原来的myql的root的密码;
修改的用户都以root为列.一.拥有原来的myql的root的密码: 方法一:在mysql系统外,使用mysqladmin# mysqladmin -u root -p password " ...
- JS对象和数组
/* 数组和对象 [JavaScript 权威指南 第五版] */ /* 对象: 是一个无序属性集合, 每个属性都有自己的名字和值 */ /* 创建对象简单方法, 对象直接量 */ var obj = ...
- OpenVPN官方资源下载和官方教程入口
官方资源: https://openvpn.net/index.php/open-source/downloads.html 2.4.4版本下载:(链接: https://pan.baidu.com/ ...
- Oracle Extended Tracing
Definitions A trace file is a file that contains diagnostic data used to investigate problems. Als ...
- 【redis】在spring boot2.0中使用redis的StringRedisTemplate 自动注入@Autowired
1.使用opv.increment 达到增量的效果[判断某个用户 是第几次做这种操作] @RequestMapping("createCode") @RestController ...
- Log4j 日志级别
转自:http://michales003.iteye.com/blog/1160605 日志记录器(Logger)是日志处理的核心组件.log4j具有5种正常级别(Level).: 1.static ...