fix: dimension filter query
This commit is contained in:
@@ -493,6 +493,53 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters):
|
||||
'company': filters.get("company", "")
|
||||
})
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_filtered_dimensions(doctype, txt, searchfield, start, page_len, filters):
|
||||
from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import get_dimension_filter_map
|
||||
dimension_filters = get_dimension_filter_map()
|
||||
dimension_filters = dimension_filters.get((filters.get('dimension'),filters.get('account')))
|
||||
group_condition = ''
|
||||
company_condition = ''
|
||||
|
||||
meta = frappe.get_meta(doctype)
|
||||
|
||||
if meta.is_tree:
|
||||
group_condition = 'and is_group = 0 '
|
||||
|
||||
if meta.has_field('company'):
|
||||
company_condition = 'and company = %s ' % (frappe.db.escape(filters.get('company')))
|
||||
|
||||
if dimension_filters:
|
||||
if dimension_filters['allow_or_restrict'] == 'Allow':
|
||||
query_selector = 'in'
|
||||
else:
|
||||
query_selector = 'not in'
|
||||
|
||||
if len(dimension_filters['allowed_dimensions']) == 1:
|
||||
dimensions = tuple(dimension_filters['allowed_dimensions'] * 2)
|
||||
else:
|
||||
dimensions = tuple(dimension_filters['allowed_dimensions'])
|
||||
|
||||
result = frappe.db.sql("""SELECT name from `tab{doctype}` where
|
||||
name {query_selector} {restricted}
|
||||
{group_condition} {company_condition}
|
||||
and {key} LIKE %(txt)s""".format(
|
||||
doctype=doctype, query_selector=query_selector, restricted=dimensions,
|
||||
group_condition = group_condition,
|
||||
company_condition = company_condition,
|
||||
key=searchfield), {
|
||||
'txt': '%' + txt + '%'
|
||||
})
|
||||
|
||||
return result
|
||||
else:
|
||||
return frappe.db.sql("""
|
||||
SELECT name from `tab{doctype}` where
|
||||
{key} LIKE %(txt)s {group_condition} {company_condition}"""
|
||||
.format(doctype=doctype, key=searchfield,
|
||||
group_condition=group_condition, company_condition=company_condition),
|
||||
{ 'txt': '%' + txt + '%'})
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
|
||||
Reference in New Issue
Block a user