转自: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方法的使用的更多相关文章

  1. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

  2. OpenERP ORM 对象方法列表

    OpenERP对象支持的字段类型有,基础类型:char, text, boolean, integer, float, date, time, datetime, binary:复杂类型:select ...

  3. openerp经典收藏 对象的预定义方法(转载)

    对象的预定义方法 原文:http://shine-it.net/index.php/topic,2159.15.html 每个OpenERP的对象都有一些预定义方法,这些方法定义在基类osv.osv中 ...

  4. Odoo模型的内置方法(可按需重写)

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826222.html ==========模型层面========== 一:_table_exist 检查 ...

  5. mapreduce多文件输出的两方法

    mapreduce多文件输出的两方法   package duogemap;   import java.io.IOException;   import org.apache.hadoop.conf ...

  6. 【.net 深呼吸】细说CodeDom(6):方法参数

    本文老周就给大伙伴们介绍一下方法参数代码的生成. 在开始之前,先补充一下上一篇烂文的内容.在上一篇文章中,老周检讨了 MemberAttributes 枚举的用法,老周此前误以为该枚举不能进行按位操作 ...

  7. IE6、7下html标签间存在空白符,导致渲染后占用多余空白位置的原因及解决方法

    直接上图:原因:该div包含的内容是靠后台进行print操作,输出的.如果没有输出任何内容,浏览器会默认给该空白区域添加空白符.在IE6.7下,浏览器解析渲染时,会认为空白符也是占位置的,默认其具有字 ...

  8. 多线程爬坑之路-Thread和Runable源码解析之基本方法的运用实例

    前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...

  9. [C#] C# 基础回顾 - 匿名方法

    C# 基础回顾 - 匿名方法 目录 简介 匿名方法的参数使用范围 委托示例 简介 在 C# 2.0 之前的版本中,我们创建委托的唯一形式 -- 命名方法. 而 C# 2.0 -- 引进了匿名方法,在 ...

随机推荐

  1. 洛谷——P1743 矩阵 III

    P1743 矩阵 III 题目背景 usqwedf 改编系列题. 题目描述 给定一个n*m的矩阵,问从左上角走到右下角有多少条路径. 输入输出格式 输入格式: 一行两个正整数 n,m 输出格式: 路径 ...

  2. web worker 实践

    1.web worker 在浏览器中JavaScript主线程与UI渲染线程是互斥的.即UI渲染线程会阻塞JavaScript线程的运行. web worker允许创建工作线程,并可以与JavaScr ...

  3. VB 中DTpicker日期控件的运用

    1.如何加载 VB默认的控件栏中是没有DTpicker日期控件的,添加过程:工具--部件--控件--"Microsoft  Windows Common Controls-2.6.0&quo ...

  4. [P2526][SHOI2001]小狗散步

    Link: P2526 传送门 Solution: 一道提示非常到位的题目 题面中强调了在两个路径相邻点间只能再去至多一个点,且每个点只计算一次贡献 于是明显可以将原题看作询问在两个不相交点集间最多能 ...

  5. 【POJ】1088滑雪

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 97335   Accepted: 36911 Description ...

  6. BZOJ 1202 [HNOI2005]狡猾的商人(并查集)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1202 [题目大意] 给出一些区间和的数值,问是否存在矛盾 [题解] 用并查集维护前缀和 ...

  7. 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration

    题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...

  8. NTP安全漏洞公告

        NTP服务今天公告了几个高危漏洞,大概信息如下: 描述:包含缓冲区溢出等多个高危或低危漏洞. 危害:可以利用获取服务器权限完全控制服务器,至少可以造成服务器崩溃. 影响范围:只有升级到4.2. ...

  9. Process.Start() 传递参数中有空格问题

    项目->   (工程名)属性-> 调试-> 命令行参数 1.在命令行下执行 参数之间用空格分隔开就可以了,如果参数有空格,以双引号风格 Test   aa   "bb   ...

  10. 【java】随机生成6位的数字 /生成例如010 045这样的三位数

    int radomInt = new Random().nextInt(999999) @org.junit.Test public void testName() throws Exception ...