Skip to content

Commit

Permalink
fix: support child tables in count with limit
Browse files Browse the repository at this point in the history
(cherry picked from commit 1fa7cc7)
  • Loading branch information
ankush authored and mergify[bot] committed Mar 12, 2024
1 parent 5c1bca8 commit d8a797b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions frappe/desk/reportview.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,14 @@ def get_count() -> int:
args.distinct = sbool(args.distinct)
distinct = "distinct " if args.distinct else ""
args.limit = cint(args.limit)
fieldname = f"{distinct}`tab{args.doctype}`.name"

if args.limit:
# Only "count until this limit"
args.fields = [f"`tab{args.doctype}`.name"]
args.fields = [fieldname]
partial_query = execute(**args, run=0)
count = frappe.db.sql(
f"""with records as ( {partial_query} )
select count(*) from records""",
)[0][0]
count = frappe.db.sql(f"""select count(*) from ( {partial_query} ) p""")[0][0]
else:
args.fields = [f"count({distinct}`tab{args.doctype}`.name) as total_count"]
args.fields = [f"count({fieldname}) as total_count"]
count = execute(**args)[0].get("total_count")

return count
Expand Down
2 changes: 1 addition & 1 deletion frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

let count_str;
if (this.total_count === this.count_upper_bound) {
count_str = `${format_number(count_str - 1, null, 0)}+`;
count_str = `${format_number(this.total_count - 1, null, 0)}+`;
} else {
count_str = format_number(this.total_count, null, 0);
}
Expand Down

0 comments on commit d8a797b

Please sign in to comment.