提交 fd679109 authored 作者: 贺阳's avatar 贺阳

批量查询的优化

上级 ad79df9f
......@@ -7,7 +7,7 @@
This module provides a mixin that allows searching multiple records at once using special syntax:
{term1 term2 term3}
[term1, term2, term3]
空格,逗号,换行 这些可以在系统参数进行自定义,用{}或[]包围
The mixin can be inherited by any model to enable multi-search functionality.
""",
'author': 'SeaTek',
......
......@@ -14,38 +14,53 @@ class BaseModel(models.AbstractModel):
"""Check is multi-search pattern or not."""
if not isinstance(value, str):
return False, []
if value.startswith('{') and value.endswith('}') or value.startswith('[') and value.endswith(']'):
content = value[1:-1]
if not content:
return False, []
# 直接根据逗号或空格或换行符分割
separators = self.env['ir.config_parameter'].sudo().get_param('multi_record_search_separators',
default="[',', ',', ' ', '\n', ' ']")
separators = eval(separators)
# 判断value是否包含分隔符
if any(sep in value for sep in separators) or value.startswith('{') and value.endswith('}') or value.startswith(
'[') and value.endswith(']'):
print('value:%s' % value)
# {record1 record2 ...}
if value.startswith('{') and value.endswith('}'):
content = value[1:-1].strip()
if not content:
return False, []
search_terms = [term.strip() for term in content.split() if term.strip()]
return bool(search_terms), search_terms
# [record1, record2, ...]
elif value.startswith('[') and value.endswith(']'):
content = value[1:-1].strip()
if not content:
return False, []
search_terms = [term.strip() for term in content.split(',') if term.strip()]
return bool(search_terms), search_terms
else:
for sep in separators:
value = value.replace(sep, '!')
search_terms = [term.strip() for term in value.split('!') if term.strip()]
content = content.replace(sep, '!')
search_terms = [term.strip() for term in content.split('!') if term.strip()]
if search_terms:
return bool(search_terms), search_terms
# search_terms = [term.strip() for term in content.split() if term.strip()]
return bool(search_terms), search_terms
# # 直接根据逗号或空格或换行符分割
# separators = self.env['ir.config_parameter'].sudo().get_param('multi_record_search_separators',
# default="[',', ',', ' ', '\n', ' ']")
# separators = eval(separators)
# # 判断value是否包含分隔符
# if any(sep in value for sep in separators) or value.startswith('{') and value.endswith('}') or value.startswith(
# '[') and value.endswith(']'):
# print('value:%s' % value)
# # {record1 record2 ...}
# if value.startswith('{') and value.endswith('}'):
# content = value[1:-1].strip()
# if not content:
# return False, []
#
# search_terms = [term.strip() for term in content.split() if term.strip()]
# return bool(search_terms), search_terms
#
# # [record1, record2, ...]
# elif value.startswith('[') and value.endswith(']'):
# content = value[1:-1].strip()
# if not content:
# return False, []
#
# search_terms = [term.strip() for term in content.split(',') if term.strip()]
# return bool(search_terms), search_terms
# else:
#
# for sep in separators:
# value = value.replace(sep, '!')
# search_terms = [term.strip() for term in value.split('!') if term.strip()]
# if search_terms:
# return bool(search_terms), search_terms
return False, []
@api.model
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论