|
|
@@ -185,8 +185,8 @@ class DatabaseQuery(object): |
|
|
|
# add tables from fields |
|
|
|
if self.fields: |
|
|
|
for f in self.fields: |
|
|
|
if ( not ("tab" in f and "." in f) ) or ("locate(" in f): continue |
|
|
|
|
|
|
|
if ( not ("tab" in f and "." in f) ) or ("locate(" in f) or ("count(" in f): |
|
|
|
continue |
|
|
|
|
|
|
|
table_name = f.split('.')[0] |
|
|
|
if table_name.lower().startswith('group_concat('): |
|
|
@@ -571,38 +571,6 @@ def get_list(doctype, *args, **kwargs): |
|
|
|
kwargs.pop('cmd', None) |
|
|
|
return DatabaseQuery(doctype).execute(None, *args, **kwargs) |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def get_count(doctype, filters=None): |
|
|
|
if filters: |
|
|
|
filters = json.loads(filters) |
|
|
|
|
|
|
|
if is_parent_only_filter(doctype, filters): |
|
|
|
if isinstance(filters, list): |
|
|
|
filters = frappe.utils.make_filter_dict(filters) |
|
|
|
|
|
|
|
return frappe.db.count(doctype, filters=filters) |
|
|
|
|
|
|
|
else: |
|
|
|
# If filters contain child table as well as parent doctype - Join |
|
|
|
tables, conditions = ['`tab{0}`'.format(doctype)], [] |
|
|
|
for f in filters: |
|
|
|
fieldname = '`tab{0}`.{1}'.format(f[0], f[1]) |
|
|
|
table = '`tab{0}`'.format(f[0]) |
|
|
|
|
|
|
|
if table not in tables: |
|
|
|
tables.append(table) |
|
|
|
|
|
|
|
conditions.append('{fieldname} {operator} "{value}"'.format(fieldname=fieldname, |
|
|
|
operator=f[2], value=f[3])) |
|
|
|
|
|
|
|
if doctype != f[0]: |
|
|
|
join_condition = '`tab{child_doctype}`.parent =`tab{doctype}`.name'.format(child_doctype=f[0], doctype=doctype) |
|
|
|
if join_condition not in conditions: |
|
|
|
conditions.append(join_condition) |
|
|
|
|
|
|
|
return frappe.db.sql_list("""select count(*) from {0} |
|
|
|
where {1}""".format(','.join(tables), ' and '.join(conditions)), debug=0) |
|
|
|
|
|
|
|
def is_parent_only_filter(doctype, filters): |
|
|
|
#check if filters contains only parent doctype |
|
|
|
only_parent_doctype = True |
|
|
|