浏览代码

Merge pull request #15722 from hrwX/virtual_dt

feat: get_count, get_stats for virtual doctype
version-14
mergify[bot] 3 年前
committed by GitHub
父节点
当前提交
028bb9eb06
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 4 个文件被更改,包括 53 次插入10 次删除
  1. +12
    -1
      frappe/core/doctype/test/test.py
  2. +33
    -8
      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)]


+ 33
- 8
frappe/desk/reportview.py 查看文件

@@ -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")


+ 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');
}


正在加载...
取消
保存