ODOO 10 Uncaught TypeError: split is not a function
ODOO 10 Uncaught TypeError: split is not a function
当我尝试 get/search 在我的自定义模型中使用 Many2one 字段的合作伙伴名称时,我遇到了这个问题。
我正在尝试与 sale/Quotation 模块中的 partner_id 声明进行比较,但我没有发现任何区别,顺便说一句,当我尝试在报价中搜索客户名称时,此错误不会显示.
声明字段:*.py
partner_id = fields.Many2one('res.partner', string="Client", required=True)
声明字段:*.xml
<group name="partner_info" string="Info client">
<field name="partner_id" />
<label for="street" string="Address"/>
<div class="o_address_format">
<field name="street" placeholder="Street..." class="o_address_street" />
<field name="city" placeholder="City" class="o_address_city" />
<field name="state_id" class="o_address_state" placeholder="State" options="{"no_open": True}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip" />
</div>
<label for="street" string="Contact"/>
<div name="contact">
<field name="phone" widget="phone" placeholder="Tél ° "/>
<field name="email" widget="email" placeholder="E-mail"/>
</div>
</group>
提前致谢
经过深入搜索,我找到了问题的根源,当我们在合作伙伴字段中输入一个字母时,它会自动调用基础模块中的函数name_search,在[中搜索=30=] table 使用 SQL 查询 :
select id
from res_partner
where 'entered value' [ '=' or 'like' or 'ilike' or '=like' or
'=ilike'] [email, or name, ref ]...`;
这个查询return一个元组列表
[(id1, 'partner name1'), (id2, 'partner name2')]
和函数 return 每个元组的第二个榆树 是合作伙伴的名字,但是如果你有一些名字字段为空的合作伙伴,就会显示错误,这就解释了为什么有些字母不会生成错误消息。有些信件不会生成错误消息,因为 SQL 查询搜索基于多个字段,如电子邮件、参考、合作伙伴姓名。
而且这个功能只是在合作伙伴中存在,而不是在每个 table 中说明该功能的主要 objective 是让我们可以根据其他字段进行搜索 [email, reference ...]
函数路径:/addons/base/res/res_partner.py
第640行
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
if args is None:
args = []
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
self.check_access_rights('read')
where_query = self._where_calc(args)
self._apply_ir_rules(where_query, 'read')
from_clause, where_clause, where_clause_params = where_query.get_sql()
where_str = where_clause and (" WHERE %s AND " % where_clause) or ' WHERE '
# 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:]
unaccent = get_unaccent_wrapper(self.env.cr)
query = """SELECT id
FROM res_partner
{where} ({email} {operator} {percent}
OR {display_name} {operator} {percent}
OR {reference} {operator} {percent})
-- don't panic, trust postgres bitmap
ORDER BY {display_name} {operator} {percent} desc,
{display_name}
""".format(where=where_str,
operator=operator,
email=unaccent('email'),
display_name=unaccent('display_name'),
reference=unaccent('ref'),
percent=unaccent('%s'))
where_clause_params += [search_name]*4
if limit:
query += ' limit %s'
where_clause_params.append(limit)
self.env.cr.execute(query, where_clause_params)
partner_ids = map(lambda x: x[0], self.env.cr.fetchall())
if partner_ids:
return self.browse(partner_ids).name_get()
else:
return []
return super(Partner, self).name_search(name, args, operator=operator, limit=limit)
错误行:
if partner_ids:
return self.browse(partner_ids).name_get()
else:
return []
当我尝试 get/search 在我的自定义模型中使用 Many2one 字段的合作伙伴名称时,我遇到了这个问题。 我正在尝试与 sale/Quotation 模块中的 partner_id 声明进行比较,但我没有发现任何区别,顺便说一句,当我尝试在报价中搜索客户名称时,此错误不会显示.
声明字段:*.py
partner_id = fields.Many2one('res.partner', string="Client", required=True)
声明字段:*.xml
<group name="partner_info" string="Info client">
<field name="partner_id" />
<label for="street" string="Address"/>
<div class="o_address_format">
<field name="street" placeholder="Street..." class="o_address_street" />
<field name="city" placeholder="City" class="o_address_city" />
<field name="state_id" class="o_address_state" placeholder="State" options="{"no_open": True}"/>
<field name="zip" placeholder="ZIP" class="o_address_zip" />
</div>
<label for="street" string="Contact"/>
<div name="contact">
<field name="phone" widget="phone" placeholder="Tél ° "/>
<field name="email" widget="email" placeholder="E-mail"/>
</div>
</group>
提前致谢
经过深入搜索,我找到了问题的根源,当我们在合作伙伴字段中输入一个字母时,它会自动调用基础模块中的函数name_search,在[中搜索=30=] table 使用 SQL 查询 :
select id
from res_partner
where 'entered value' [ '=' or 'like' or 'ilike' or '=like' or
'=ilike'] [email, or name, ref ]...`;
这个查询return一个元组列表
[(id1, 'partner name1'), (id2, 'partner name2')]
和函数 return 每个元组的第二个榆树 是合作伙伴的名字,但是如果你有一些名字字段为空的合作伙伴,就会显示错误,这就解释了为什么有些字母不会生成错误消息。有些信件不会生成错误消息,因为 SQL 查询搜索基于多个字段,如电子邮件、参考、合作伙伴姓名。
而且这个功能只是在合作伙伴中存在,而不是在每个 table 中说明该功能的主要 objective 是让我们可以根据其他字段进行搜索 [email, reference ...]
函数路径:/addons/base/res/res_partner.py
第640行
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
if args is None:
args = []
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
self.check_access_rights('read')
where_query = self._where_calc(args)
self._apply_ir_rules(where_query, 'read')
from_clause, where_clause, where_clause_params = where_query.get_sql()
where_str = where_clause and (" WHERE %s AND " % where_clause) or ' WHERE '
# 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:]
unaccent = get_unaccent_wrapper(self.env.cr)
query = """SELECT id
FROM res_partner
{where} ({email} {operator} {percent}
OR {display_name} {operator} {percent}
OR {reference} {operator} {percent})
-- don't panic, trust postgres bitmap
ORDER BY {display_name} {operator} {percent} desc,
{display_name}
""".format(where=where_str,
operator=operator,
email=unaccent('email'),
display_name=unaccent('display_name'),
reference=unaccent('ref'),
percent=unaccent('%s'))
where_clause_params += [search_name]*4
if limit:
query += ' limit %s'
where_clause_params.append(limit)
self.env.cr.execute(query, where_clause_params)
partner_ids = map(lambda x: x[0], self.env.cr.fetchall())
if partner_ids:
return self.browse(partner_ids).name_get()
else:
return []
return super(Partner, self).name_search(name, args, operator=operator, limit=limit)
错误行:
if partner_ids:
return self.browse(partner_ids).name_get()
else:
return []