转自: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. Struts2中使用Session

    嗯,没错,过了这么长时间我还在做我的注册和登录. 登陆的部分自然是从数据库中查找响应的用户信息,然后把一个user放到session里, Action中代码如下: public String Logi ...

  2. HTML5 form内button

    突然发现奇怪的事 在html5 中bottn 的type不是submit但是单击的时候它自己就提交表单了. 然后在一查就看到 问题解决,加上type=“button”

  3. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  4. [BZOJ4004][JLOI2015]装备购买(贪心+线性基)

    求最小权极大线性无关组. 先将所有向量按权值排序,从小到大依次判断,若能被前面已选向量线性表出则不选,这样一定最优. 据说是用拟阵来证明,但感性理解一下感觉比较显然,首先这样个数一定是最多的,其次对于 ...

  5. JZYZOJ1454 NOIP2015 D2T3_运输计划 二分 差分数组 lca tarjan 树链剖分

    http://172.20.6.3/Problem_Show.asp?id=1454 从这道题我充分认识到我的脑子里好多水orz. 如果知道了这个要用二分和差分写,就没什么思考上的难点了(屁咧你写了一 ...

  6. 【扩展欧几里得】Codeforces Round #406 (Div. 2) A. The Monster

    扩欧,a+bx=c+dx,输出x>=0且y>=0,且a+bx最小的解. 要注意不能只保证x非负,还得看看能否保证y也非负. #include<cstdio> #include& ...

  7. 20172333 2017-2018-2 《Java程序设计》第2周学习总结

    20172333 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 1.了解print与println的用法区别. 2.有关于"+"的基本用 ...

  8. [转]Spring MVC 事务配置

    Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法:  <tx:advice/>就是告诉事务管理器:怎么做 ...

  9. FTP具有两种模式

    FTP具有两种模式,分别是port模式(也叫主动模式)和pasv模式(也叫被动模式),怎么来理解这两种模式呢?我来打个比喻吧,在主动模式下:客户端给服务器端的21端口发命令说,我要下载什么什么,并且还 ...

  10. Hive 内建操作符与函数开发——深入浅出学Hive

    第一部分:关系运算 Hive支持的关系运算符 •常见的关系运算符 •等值比较: = •不等值比较: <> •小于比较: < •小于等于比较: <= •大于比较: > •大 ...