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" ...
随机推荐
- 使用火蜘蛛采集器Firespider采集天猫商品数据并上传到微店
有很多朋友都需要把天猫的商品迁移到微店上去.可在天猫上的商品数据非常复杂,淘宝开放接口禁止向外提供数据,一般的采集器对ajax数据采集的支持又不太好. 还有现在有了火蜘蛛采集器,经过一定的配置,终于把 ...
- windows mobile 只能运行一个程序实例
static class Program { [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastErr ...
- 【小梅哥SOPC学习笔记】给NIOS II CPU增加看门狗定时器并使用
给NIOS II CPU增加看门狗定时器并使用 配置看门狗定时器: 1. 设置计时溢出时间为1秒 2. 计数器位宽为32位 3. 勾选No Start/Stop control bits 4. 勾选F ...
- C++对象在内存中的布局
(1)C++对象模型 (2)单一继承无虚函数 (3)单一继承有虚函数 (4)多重继承 (5)虚拟继承(vc++) (6)虚拟继承(g++) 参考:<深度探索C++对象模型>
- MIDA Converter Basic patched for RAD Studio 10.1.2 Berlin (VCL转换到FMX)
Mida is the only way to try to convert your project from VCL to FireMonkey. Version after version, M ...
- Android-bindService远程服务(Aidl)-传递对象
之前上一篇讲解到本地服务,本地服务只能在自身APP中Activity访问Service,调用Service里面到方法等操作 如果想A应用访问B应用里面的方法,属于跨进程调用,如果Android不特供这 ...
- [LeetCode 题解]: Permutation Sequcence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 数独高阶技巧入门之七——AIC & Nice Loop
AIC(交替推理链,Alternate Inference Chain) 在简单异数链一文中我们介绍过XY-Chain技法,AIC可以看作是XY-Chain的扩展.有别于XY-Chain仅局限于双值格 ...
- C++静态成员和非静态成员的区别和使用
C++静态成员和非静态成员的区别和使用 对象与对象之间的成员变量是相互独立的.要想共用数据,则需要使用静态成员和静态方法. 只要在类中声明静态成员变量,即使不定义对象,也可以为静态成员变量分配空间,进 ...
- oracle数据库中将clob字段内容利用java提取出至文本文档中
代码段: 1.执行clob转String public static String ClobToString(Clob sc) throws SQLException, IOException { S ...