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" ...
随机推荐
- 关于利用word发布文章到博客
目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...
- review一个javascript功能函数
近半年来一直觉得自己在技术上好像左右挣扎,技术没啥提升,看书看不进,自学还挺慢.写出来的东西,自己都觉得不满意.让自己也用庸人自扰的感觉. 最近,在工作中,有一个小小的功能需要实现,这个功能非常简单, ...
- 设置emacs启动窗口的两种方法
1. 设置位置和大小 ;;设置窗口位置为屏库左上角(0,0) (set-frame-position (selected-frame) 0 0) ;;设置宽和高 (set-frame-width (s ...
- 敏捷软件开发:原则、模式与实践——第11章 DIP:依赖倒置原则
第11章 DIP:依赖倒置原则 DIP:依赖倒置原则: a.高层模块不应该依赖于低层模块.二者都应该依赖于抽象. b.抽象不应该依赖于细节.细节应该依赖于抽象. 11.1 层次化 下图展示了一个简单的 ...
- Ubuntu下安装配置android sdk及其环境变量
同理,这里介绍的是手动安装方法~ *系统;Ubuntu 16.4 1.下载Android sdk,直接在系统自带的firefox浏览器输入 http://tools.android-studio.or ...
- Head First Python之4持久存储
open()用法 # encoding:utf-8 try: # 写模式打开文件,若不存在该文件,则创建 out = open("data.out", "w") ...
- AC620教程 第十五节 8位7段数码管驱动设计与验证
本章导读 电子系统中常用的显示设备有数码管.LCD液晶以及VGA显示器等.其中数码管又可分为段式显示(7段.米字型等)以及点阵显示(8*8.16*16等),LCD液晶的应用可以分为字符式液晶(1602 ...
- Rsync+Inotify实现文件自动同步
1>rsync概述 rsync的优点与不足 rsync与传统的cp.tar备份方式相比,rsync具有安全性高.备份迅速.支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求 ...
- RzToolbutton用法
- leetcode 有效的数独
判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1-9 在每一个以粗实线分隔的 ...