fix: batch listing for current day batches

This commit is contained in:
Jannat Patel
2025-01-16 11:43:56 +05:30
parent 0d1464c5e9
commit b4c7338b76
5 changed files with 52 additions and 7 deletions

View File

@@ -35,8 +35,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Course",
"options": "LMS Course",
"reqd": 1
"options": "LMS Course"
},
{
"fieldname": "expiry_date",
@@ -114,7 +113,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-11 11:37:20.419956",
"modified": "2025-01-16 11:42:51.449506",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Certificate",

View File

@@ -1889,6 +1889,28 @@ def get_batches(filters=None, start=0, page_length=20, order_by="start_date"):
page_length=page_length,
)
print(batches)
batchType = get_batch_type(filters)
if batchType == "upcoming":
batches_to_remove = list(
filter(
lambda batch: getdate(batch.start_date) == getdate()
and get_time_str(batch.start_time) < nowtime(),
batches,
)
)
print(batches_to_remove)
batches = [batch for batch in batches if batch not in batches_to_remove]
elif batchType == "archived":
batches_to_remove = list(
filter(
lambda batch: getdate(batch.start_date) == getdate()
and get_time_str(batch.start_time) >= nowtime(),
batches,
)
)
batches = [batch for batch in batches if batch not in batches_to_remove]
for batch in batches:
batch.instructors = get_instructors(batch.name)
students_count = frappe.db.count("Batch Student", {"parent": batch.name})
@@ -1903,3 +1925,16 @@ def get_batches(filters=None, start=0, page_length=20, order_by="start_date"):
batch.price = fmt_money(batch.amount, 0, batch.currency)
return batches
def get_batch_type(filters):
start_date_filter = filters.get("start_date")
batchType = None
if start_date_filter:
sign = start_date_filter[0]
if ">" in sign:
batchType = "upcoming"
elif "<" in sign:
batchType = "archived"
return batchType

View File

@@ -18,6 +18,7 @@ def get_context():
frappe.db.commit() # nosemgrep
context.csrf_token = csrf_token
capture("active_site", "lms")
context.favicon = frappe.db.get_single_value("Website Settings", "favicon")
return context