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" ...
随机推荐
- linux 不在sudoers文件中、普通用户获得sudo权限
现在要让jack用户获得sudo使用权 切换到超级用户root $su root 查看/etc/sudoers权限,可以看到当前权限为440 $ ls -all /etc/sudoers -r--r- ...
- zookeeper学习及安装
HBase提示已创建表,但是list查询时,却显示表不存在. https://blog.csdn.net/liu16659/article/details/80216085 http://archiv ...
- 洛谷 P2146 [NOI2015]软件包管理器 (树链剖分模板题)
题目描述 Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从软件源下载软件包,同时自动解决所有的依赖(即下载安装这个 ...
- Git代码行统计命令集
统计某人的代码提交量,包括增加,删除: git log --author="$(git config --get user.name)" --pretty=tformat: --n ...
- memcached整理の缓存问题
声明:博客来源http://www.cnblogs.com/AloneSword/p/3931905.html,谢谢他的分享! 缓存穿透与缓存雪崩 缓存系统不得不考虑的另一个问题是缓存穿透与失效时的雪 ...
- Android-bindService远程服务(Aidl)-传递对象
之前上一篇讲解到本地服务,本地服务只能在自身APP中Activity访问Service,调用Service里面到方法等操作 如果想A应用访问B应用里面的方法,属于跨进程调用,如果Android不特供这 ...
- [LeetCode 题解]: String to Interger (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- How can i use iptables on centos 7 or fedora?
http://stackoverflow.com/questions/24756240/how-can-i-use-iptables-on-centos-7 # sudo service iptabl ...
- RobotFramework中查询数据库相关
先要安装:robotframework-databaselibrary,并导入RIDE 封装“连接数据库”关键字,内容如下: 断开数据库:Disconnect From Database,没有参数 一 ...
- sql分组拼接字段
--联查select n.*,t.Name from News n join Type_News tn on n.Id=tn.NId join Types t on t.Id=tn.TId --拼接并 ...