Ver a proveniência

feat: get_count, get_stats for virtual doctype

version-14
hrwx há 3 anos
ascendente
cometimento
26a70e3cf1
4 ficheiros alterados com 48 adições e 9 eliminações
  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 Ver ficheiro

@@ -31,4 +31,15 @@ class test(Document):
def get_value(self, fields, filters, **kwargs): def get_value(self, fields, filters, **kwargs):
# return [] # return []
with open("data_file.json", "r") as read_file: 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 Ver ficheiro

@@ -29,17 +29,31 @@ def get():
@frappe.whitelist() @frappe.whitelist()
@frappe.read_only() @frappe.read_only()
def get_list(): 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.whitelist()
@frappe.read_only() @frappe.read_only()
def get_count(): def get_count():
args = get_form_params() 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): def execute(doctype, *args, **kwargs):
return DatabaseQuery(doctype).execute(*args, **kwargs) return DatabaseQuery(doctype).execute(*args, **kwargs)
@@ -438,7 +452,14 @@ def get_sidebar_stats(stats, doctype, filters=None):
if filters is None: if filters is None:
filters = [] 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.whitelist()
@frappe.read_only() @frappe.read_only()
@@ -560,7 +581,7 @@ def get_match_cond(doctype, as_condition=True):
return ((' and ' + cond) if cond else "").replace("%", "%%") return ((' and ' + cond) if cond else "").replace("%", "%%")


def build_match_conditions(doctype, user=None, as_condition=True): 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: if as_condition:
return match_conditions.replace("%", "%%") return match_conditions.replace("%", "%%")
else: else:


+ 6
- 0
frappe/modules/utils.py Ver ficheiro

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


def get_list(self, args): def get_list(self, args):
pass

def get_count(self, args):
pass

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


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


+ 2
- 1
frappe/public/js/frappe/list/list_sidebar.js Ver ficheiro

@@ -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) || [] filters: (me.list_view.filter_area ? me.list_view.get_filters_for_args() : me.default_filters) || []
}, },
callback: function(r) { 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'); let stats_dropdown = me.sidebar.find('.list-stats-dropdown');
frappe.utils.setup_search(stats_dropdown, '.stat-link', '.stat-label'); frappe.utils.setup_search(stats_dropdown, '.stat-link', '.stat-label');
} }


Carregando…
Cancelar
Guardar