|
|
@@ -19,7 +19,7 @@ from frappe.utils import add_user_info |
|
|
|
def get(): |
|
|
|
args = get_form_params() |
|
|
|
# If virtual doctype get data from controller het_list method |
|
|
|
if frappe.db.get_value("DocType", filters={"name": args.doctype}, fieldname="is_virtual"): |
|
|
|
if is_virtual_doctype(args.doctype): |
|
|
|
controller = get_controller(args.doctype) |
|
|
|
data = compress(controller(args.doctype).get_list(args)) |
|
|
|
else: |
|
|
@@ -29,17 +29,31 @@ def get(): |
|
|
|
@frappe.whitelist() |
|
|
|
@frappe.read_only() |
|
|
|
def get_list(): |
|
|
|
# uncompressed (refactored from frappe.model.db_query.get_list) |
|
|
|
return execute(**get_form_params()) |
|
|
|
args = get_form_params() |
|
|
|
|
|
|
|
if is_virtual_doctype(args.doctype): |
|
|
|
controller = get_controller(args.doctype) |
|
|
|
data = controller(args.doctype).get_list(args) |
|
|
|
else: |
|
|
|
# uncompressed (refactored from frappe.model.db_query.get_list) |
|
|
|
data = execute(**args) |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
@frappe.read_only() |
|
|
|
def get_count(): |
|
|
|
args = get_form_params() |
|
|
|
|
|
|
|
distinct = 'distinct ' if args.distinct=='true' else '' |
|
|
|
args.fields = [f"count({distinct}`tab{args.doctype}`.name) as total_count"] |
|
|
|
return execute(**args)[0].get('total_count') |
|
|
|
if is_virtual_doctype(args.doctype): |
|
|
|
controller = get_controller(args.doctype) |
|
|
|
data = controller(args.doctype).get_count(args) |
|
|
|
else: |
|
|
|
distinct = 'distinct ' if args.distinct=='true' else '' |
|
|
|
args.fields = [f"count({distinct}`tab{args.doctype}`.name) as total_count"] |
|
|
|
data = execute(**args)[0].get('total_count') |
|
|
|
|
|
|
|
return data |
|
|
|
|
|
|
|
def execute(doctype, *args, **kwargs): |
|
|
|
return DatabaseQuery(doctype).execute(*args, **kwargs) |
|
|
@@ -438,7 +452,14 @@ def get_sidebar_stats(stats, doctype, filters=None): |
|
|
|
if filters is None: |
|
|
|
filters = [] |
|
|
|
|
|
|
|
return {"stats": get_stats(stats, doctype, filters)} |
|
|
|
if is_virtual_doctype(doctype): |
|
|
|
controller = get_controller(doctype) |
|
|
|
args = {"stats": stats, "filters": filters} |
|
|
|
data = controller(doctype).get_stats(args) |
|
|
|
else: |
|
|
|
data = get_stats(stats, doctype, filters) |
|
|
|
|
|
|
|
return {"stats": data} |
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
@frappe.read_only() |
|
|
@@ -560,7 +581,7 @@ def get_match_cond(doctype, as_condition=True): |
|
|
|
return ((' and ' + cond) if cond else "").replace("%", "%%") |
|
|
|
|
|
|
|
def build_match_conditions(doctype, user=None, as_condition=True): |
|
|
|
match_conditions = DatabaseQuery(doctype, user=user).build_match_conditions(as_condition=as_condition) |
|
|
|
match_conditions = DatabaseQuery(doctype, user=user).build_match_conditions(as_condition=as_condition) |
|
|
|
if as_condition: |
|
|
|
return match_conditions.replace("%", "%%") |
|
|
|
else: |
|
|
@@ -598,3 +619,7 @@ def get_filters_cond(doctype, filters, conditions, ignore_permissions=None, with |
|
|
|
else: |
|
|
|
cond = '' |
|
|
|
return cond |
|
|
|
|
|
|
|
def is_virtual_doctype(doctype): |
|
|
|
return frappe.db.get_value("DocType", doctype, "is_virtual") |
|
|
|
|