openerp学习笔记 按客户电话、名称模糊查找选择客户(name_search)及客户名称自定义显示(name_get)
#同时按手机、电话、名称模糊查找选择客户
def
name_search(self, cr, user, name, args=None, operator='ilike', context=None,
limit=100):
if not
args:
args
= []
args =
args[:]
ids =
[]
if
name:
ids
= self.search(cr, user, [('mobile', 'ilike', name)]+args, limit=limit,
context=context)
if not
ids:
ids = self.search(cr, user, [('phone', 'ilike', name)]+ args, limit=limit,
context=context)
if not
ids:
ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit,
context=context)
else:
ids
= self.search(cr, user, args, limit=limit,
context=context)
return
self.name_get(cr, user, ids, context=context)

#关联客户时将客户名称自定义显示为“名称 手机”
def
name_get(self, cr, uid, ids,
context=None):
if not
ids:
return []
if isinstance(ids, (int,
long)):
ids = [ids]
reads = self.read(cr,
uid, ids, ['name', 'mobile'],
context=context)
res =
[]
for record in
reads:
name =
record['name']
if
record['mobile']:
name = name + ' ' +
record['mobile']
res.append((record['id'], name))
return res

其它代码参考:
#res_partner.name_search 合作伙伴查找选择
def
name_search(self, cr, uid, name, args=None, operator='ilike', context=None,
limit=100):
if not
args:
args
= []
if name and operator in ('=',
'ilike', '=ilike', 'like',
'=like'):
# search on the name of the contacts and of its
company
search_name =
name
if
operator in ('ilike',
'like'):
search_name = '%%%s%%' %
name
if
operator in ('=ilike',
'=like'):
operator =
operator[1:]
query_args = {'name':
search_name}
limit_str =
''
if
limit:
limit_str = ' limit
%(limit)s'
query_args['limit'] =
limit
#
TODO: simplify this in trunk with _rec_name='display_name', once
display_name
# becomes a stored
field
cr.execute('''SELECT partner.id FROM res_partner
partner
LEFT JOIN res_partner company ON partner.parent_id =
company.id
WHERE partner.email ''' + operator +''' %(name)s
OR
CASE WHEN company.id IS NULL OR partner.is_company
THEN
partner.name
ELSE
company.name || ', ' ||
partner.name
END
''' + operator + ' %(name)s ' + limit_str,
query_args)
ids = map(lambda x: x[0],
cr.fetchall())
ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit,
context=context)
if
ids:
return self.name_get(cr, uid, ids,
context)
return
super(res_partner,self).name_search(cr, uid, name, args, operator=operator,
context=context, limit=limit)
#res_partner.name_get 合作伙伴名称显示
def name_get(self, cr, uid, ids,
context=None):
if context is
None:
context = {}
if isinstance(ids,
(int,
long)):
ids = [ids]
res =
[]
for record in self.browse(cr,
uid, ids,
context=context):
name =
record.name
if record.parent_id and not
record.is_company:
name = "%s, %s" % (record.parent_id.name,
name)
if
context.get('show_address'):
name = name + "\n" + self._display_address(cr, uid, record,
without_company=True,
context=context)
name =
name.replace('\n\n','\n')
name =
name.replace('\n\n','\n')
if context.get('show_email') and
record.email:
name = "%s <%s>" % (name,
record.email)
res.append((record.id, name))
return res
#proudct_product.name_search 产品查找选择
def
name_search(self, cr, user, name='', args=None, operator='ilike', context=None,
limit=100):
if not
args:
args
= []
if
name:
ids
= self.search(cr, user, [('default_code','=',name)]+ args, limit=limit,
context=context)
if not
ids:
ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit,
context=context)
if not
ids:
# Do not merge the 2 next lines into one single search, SQL search performance
would be
abysmal
# on a database with thousands of matching products, due to the huge
merge+unique needed for
the
# OR operator (and given the fact that the 'name' lookup results come from the
ir.translation
table
# Performing a quick memory merge of ids in Python will give much better
performance
ids =
set()
ids.update(self.search(cr, user, args + [('default_code',operator,name)],
limit=limit,
context=context))
if not limit or len(ids) <
limit:
# we may underrun the limit because of dupes in the results, that's
fine
ids.update(self.search(cr, user, args + [('name',operator,name)], limit=(limit
and (limit-len(ids)) or False) ,
context=context))
ids =
list(ids)
if not
ids:
ptrn =
re.compile('(\[(.*?)\])')
res =
ptrn.search(name)
if
res:
ids = self.search(cr, user, [('default_code','=', res.group(2))] + args,
limit=limit, context=context)
else:
ids
= self.search(cr, user, args, limit=limit,
context=context)
result =
self.name_get(cr, user, ids,
context=context)
return result
#proudct_product.name_get 产品名称显示
def
name_get(self, cr, user, ids,
context=None):
if context is
None:
context = {}
if isinstance(ids,
(int,
long)):
ids = [ids]
if not
len(ids):
return []
def
_name_get(d):
name =
d.get('name','')
code =
d.get('default_code',False)
if
code:
name = '[%s] %s' %
(code,name)
if
d.get('variants'):
name = name + ' - %s' %
(d['variants'],)
return (d['id'], name)
partner_id =
context.get('partner_id', False)
result =
[]
for product in self.browse(cr,
user, ids,
context=context):
sellers = filter(lambda x: x.name.id == partner_id,
product.seller_ids)
if
sellers:
for s in
sellers:
mydict =
{
'id':
product.id,
'name': s.product_name or
product.name,
'default_code': s.product_code or
product.default_code,
'variants':
product.variants
}
result.append(_name_get(mydict))
else:
mydict =
{
'id':
product.id,
'name':
product.name,
'default_code':
product.default_code,
'variants':
product.variants
}
result.append(_name_get(mydict))
return result
openerp学习笔记 按客户电话、名称模糊查找选择客户(name_search)及客户名称自定义显示(name_get)的更多相关文章
- Spring MVC 学习笔记10 —— 实现简单的用户管理(4.3)用户登录显示全局异常信息
</pre>Spring MVC 学习笔记10 -- 实现简单的用户管理(4.3)用户登录--显示全局异常信息<p></p><p></p>& ...
- UNP学习笔记2——从一个简单的ECHO程序分析TCP客户/服务器之间的通信
1 概述 编写一个简单的ECHO(回复)程序来分析TCP客户和服务器之间的通信流程,要求如下: 客户从标准输入读入一行文本,并发送给服务器 服务器从网络输入读取这个文本,并回复给客户 客户从网络输入读 ...
- openerp学习笔记 视图中字段只变化(on_change)联动其他字段值、选择和过滤
1.修改产品数量时,自动计算产品销售金额.销售成本和销售利润<field name="num" on_change="on_change_product(produ ...
- openerp学习笔记 webkit 打印
1.webkit 打印需要安装的支持模块 请首先安装 Webkit 报表引擎(report_webkit),再安装 Webkit 报表的支持库(report_webkit_lib),该模块讲自动安装和 ...
- openerp学习笔记 跟踪状态,记录日志,发送消息
跟踪状态基础数据: kl_qingjd/kl_qingjd_data.xml <?xml version="1.0"?><openerp> <d ...
- openerp学习笔记 计算字段、关联字段(7.0中非计算字段、关联字段只读时无法修改保存的问题暂未解决)
计算字段.关联字段,对象修改时自动变更保存(当 store=True 时),当 store=False 时,默认不支持过滤和分组7.0中非计算字段.关联字段只读时无法修改保存的问题暂未解决 示例代码: ...
- openerp学习笔记 对象间关系【多对一(一对一)、一对多(主细结构)、多对多关系、自关联关系(树状结构)】
1.多对一(一对一)关系:采购单与供应商之间的关系 'partner_id':fields.many2one('res.partner', 'Supplier', required=True, sta ...
- openerp学习笔记 domain 的应用
1.在Action中定义,domain用于对象默认的搜索条件: 示例: <record id="action_orders" model="ir.actions.a ...
- openerp学习笔记 日期时间相关操作
日期格式化字符串:DATE_FORMAT = "%Y-%m-%d" 日期时间格式字符串:DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" ...
随机推荐
- 编写高质量代码改善C#程序的157个建议——建议86:Parallel中的异常处理
建议86:Parallel中的异常处理 建议85阐述了如何处理Task中的异常.由于Task的Start方法是异步启动的,所以我们需要额外的技术来完成异常处理.Parallel相对来说就要简单很多,因 ...
- 20169202 2016-2017-2《TCP/IP协议攻击》实验总结--十一周
APR缓存中毒(ARP cache poisoning) 实验原理 ARP缓存是ARP协议的重要组成部分.ARP协议运行的目标就是建立MAC地址和IP地址的映射,然后把这一映射关系保存在ARP缓存中, ...
- 使用ffmpeg+crtmpserver搭建文件的伪直播
Tutorial: How to "live stream" a media file 如何"直播"一个媒体文件 I have tried a while to ...
- xml构建
<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=346252320&site=qq ...
- .Net程序随系统开机启动(仿Foxmail托盘效果控制)
对于使.NET程序随系统开机启动,最常用的可能就是向在注册表中注册开机启动项,或是建立Windows服务,使程序随系统启动而启动.这里以WinForm程序为例,测试Demo分享,同时附上对于程序托盘的 ...
- ASP.NET MVC ActionFilterAttribute用法
- asp.net——Ajax与ashx异步请求的简单案例
Ajax与ashx异步请求的简单案例: 前台页面(aspx): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- SQL命令行修改数据库
增加列: alter table tableName add columnName varchar(30) 修改列类型:alter table tableName alter column colum ...
- 【题解】 UOJ #2. 【NOI2014】起床困难综合症
传送门 不是很简单? 考虑一下这个数的二进制位是什么,要么是1,要么是0. 然后怎么做? 因为一开始可以选0~m的数,那么二进制为中全是0的肯定是可以选的. 接着考虑全是1的怎么选? 如果全都是1的而 ...
- 深入了解java虚拟机(JVM) 第三章 内存区域----堆空间
一.堆的含义 jvm堆的区域主要是用来存放对象的实例,它的空间大小是JVM内存区域中占比重最大的,也是jvm最大的内存管理模块,最重要的是,这个区域是垃圾收集器主要管理的区域,这意味着我们在考虑垃圾回 ...