Преглед изворни кода

feat: get_count, get_stats for virtual doctype

version-14
hrwx пре 3 година
родитељ
комит
26a70e3cf1
4 измењених фајлова са 48 додато и 9 уклоњено
  1. +12
    -1
      frappe/core/doctype/test/test.py
  2. +28
    -7
      frappe/desk/reportview.py
  3. +6
    -0
      frappe/modules/utils.py
  4. +2
    -1
      frappe/public/js/frappe/list/list_sidebar.js

+ 12
- 1
frappe/core/doctype/test/test.py Прегледај датотеку

@@ -31,4 +31,15 @@ class test(Document):
def get_value(self, fields, filters, **kwargs):
# return []
with open("data_file.json", "r") as read_file:
return [json.load(read_file)]
return [json.load(read_file)]

def get_count(self, args):
# return []
with open("data_file.json", "r") as read_file:
return [json.load(read_file)]

def get_stats(self, args):
# return []
with open("data_file.json", "r") as read_file:
return [json.load(read_file)]


+ 28
- 7
frappe/desk/reportview.py Прегледај датотеку

@@ -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 frappe.db.get_value("DocType", filters={"name": args.doctype}, fieldname="is_virtual"):
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 frappe.db.get_value("DocType", filters={"name": args.doctype}, fieldname="is_virtual"):
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 frappe.db.get_value("DocType", filters={"name": doctype}, fieldname="is_virtual"):
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:


+ 6
- 0
frappe/modules/utils.py Прегледај датотеку

@@ -257,6 +257,12 @@ def make_boilerplate(template, doc, opts=None):
pass

def get_list(self, args):
pass

def get_count(self, args):
pass

def get_stats(self, args):
pass"""

with open(target_file_path, 'w') as target:


+ 2
- 1
frappe/public/js/frappe/list/list_sidebar.js Прегледај датотеку

@@ -183,7 +183,8 @@ frappe.views.ListSidebar = class ListSidebar {
filters: (me.list_view.filter_area ? me.list_view.get_filters_for_args() : me.default_filters) || []
},
callback: function(r) {
me.render_stat((r.message.stats || {})["_user_tags"]);
let stats = (r.message.stats || {})["_user_tags"] || [];
me.render_stat(stats);
let stats_dropdown = me.sidebar.find('.list-stats-dropdown');
frappe.utils.setup_search(stats_dropdown, '.stat-link', '.stat-label');
}


Loading…
Откажи
Сачувај