fix: changed certified members count based on filters

This commit is contained in:
Jannat Patel
2025-05-29 16:09:51 +05:30
parent f1bbd4eb13
commit 5ad89189c1
2 changed files with 21 additions and 9 deletions

View File

@@ -127,6 +127,7 @@ const memberCount = ref(0)
const dayjs = inject('$dayjs') const dayjs = inject('$dayjs')
onMounted(() => { onMounted(() => {
getMemberCount()
updateParticipants() updateParticipants()
}) })
@@ -138,11 +139,13 @@ const participants = createListResource({
pageLength: 30, pageLength: 30,
}) })
const count = call('lms.lms.api.get_count_of_certified_members').then( const getMemberCount = () => {
(data) => { call('lms.lms.api.get_count_of_certified_members', {
filters: filters.value,
}).then((data) => {
memberCount.value = data memberCount.value = data
} })
) }
const categories = createListResource({ const categories = createListResource({
doctype: 'LMS Certificate', doctype: 'LMS Certificate',
@@ -157,6 +160,7 @@ const categories = createListResource({
const updateParticipants = () => { const updateParticipants = () => {
updateFilters() updateFilters()
getMemberCount()
participants.update({ participants.update({
filters: filters.value, filters: filters.value,
}) })

View File

@@ -457,7 +457,7 @@ class CountDistinct(DistinctOptionFunction):
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def get_count_of_certified_members(): def get_count_of_certified_members(filters=None):
Certificate = DocType("LMS Certificate") Certificate = DocType("LMS Certificate")
query = ( query = (
@@ -466,6 +466,14 @@ def get_count_of_certified_members():
.where(Certificate.published == 1) .where(Certificate.published == 1)
) )
if filters:
for field, value in filters.items():
if field == "category":
query = query.where(
Certificate.course_title.like(f"%{value}%")
| Certificate.batch_title.like(f"%{value}%")
)
result = query.run(as_dict=True) result = query.run(as_dict=True)
return result[0]["total"] if result else 0 return result[0]["total"] if result else 0
@@ -691,13 +699,13 @@ def get_categories(doctype, filters):
@frappe.whitelist() @frappe.whitelist()
def get_members(start=0, search=""): def get_members(start=0, search=""):
"""Get members for the given search term and start index. """Get members for the given search term and start index.
Args: start (int): Start index for the query. Args: start (int): Start index for the query.
<<<<<<< HEAD <<<<<<< HEAD
search (str): Search term to filter the results. search (str): Search term to filter the results.
======= =======
search (str): Search term to filter the results. search (str): Search term to filter the results.
>>>>>>> 4869bba7bbb2fb38477d6fc29fb3b5838e075577 >>>>>>> 4869bba7bbb2fb38477d6fc29fb3b5838e075577
Returns: List of members. Returns: List of members.
""" """
filters = {"enabled": 1, "name": ["not in", ["Administrator", "Guest"]]} filters = {"enabled": 1, "name": ["not in", ["Administrator", "Guest"]]}