From b42c635cdb5834909ed26a75881eb10d322b5429 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 14 Jan 2025 17:41:46 +0530 Subject: [PATCH 1/2] refactor: improved performance and ui batch list --- frontend/src/pages/Batches.vue | 449 +++++++++++++++++---------------- lms/lms/utils.py | 57 ++++- 2 files changed, 286 insertions(+), 220 deletions(-) diff --git a/frontend/src/pages/Batches.vue b/frontend/src/pages/Batches.vue index 935ddbf0..0023dd5f 100644 --- a/frontend/src/pages/Batches.vue +++ b/frontend/src/pages/Batches.vue @@ -1,256 +1,267 @@ diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 8aa3a1ff..0f2eccd2 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -1211,7 +1211,7 @@ def get_neighbour_lesson(course, chapter, lesson): @frappe.whitelist(allow_guest=True) -def get_batches(): +def get_batches1(): batches = [] filters = {} if frappe.session.user == "Guest": @@ -1902,3 +1902,58 @@ def enroll_in_program_course(program, course): ) enrollment.save() return enrollment + + +@frappe.whitelist(allow_guest=True) +def get_batches(filters=None, start=0, page_length=20): + if not filters: + filters = {} + + if filters.get("enrolled"): + enrolled_batches = frappe.get_all( + "Batch Student", {"student": frappe.session.user}, pluck="parent" + ) + filters.update({"name": ["in", enrolled_batches]}) + del filters["enrolled"] + del filters["published"] + del filters["start_date"] + + batches = frappe.get_all( + "LMS Batch", + filters=filters, + fields=[ + "name", + "title", + "description", + "seat_count", + "paid_batch", + "amount", + "amount_usd", + "currency", + "start_date", + "end_date", + "start_time", + "end_time", + "timezone", + "published", + "category", + ], + order_by="start_date desc", + start=start, + page_length=page_length, + ) + + for batch in batches: + batch.instructors = get_instructors(batch.name) + students_count = frappe.db.count("Batch Student", {"parent": batch.name}) + + if batch.seat_count: + batch.seats_left = batch.seat_count - students_count + + if batch.paid_batch and batch.start_date >= getdate(): + batch.amount, batch.currency = check_multicurrency( + batch.amount, batch.currency, None, batch.amount_usd + ) + batch.price = fmt_money(batch.amount, 0, batch.currency) + + return batches From c6a26e5260a3b4e2da0c24b2b9ba65dda67e9b5c Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 14 Jan 2025 18:45:57 +0530 Subject: [PATCH 2/2] fix: amount rounding issue --- lms/lms/utils.py | 56 +----------------------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 0f2eccd2..24411553 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -935,7 +935,7 @@ def check_multicurrency(amount, currency, country=None, amount_usd=None): # Conversion logic starts here. Exchange rate is fetched and amount is converted. exchange_rate = get_current_exchange_rate(currency, "USD") - amount = amount * exchange_rate + amount = flt(amount * exchange_rate, 2) currency = "USD" # Check if the amount should be rounded and then apply rounding @@ -1210,60 +1210,6 @@ def get_neighbour_lesson(course, chapter, lesson): } -@frappe.whitelist(allow_guest=True) -def get_batches1(): - batches = [] - filters = {} - if frappe.session.user == "Guest": - filters.update({"start_date": [">=", getdate()], "published": 1}) - batch_list = frappe.get_all("LMS Batch", filters) - - for batch in batch_list: - batches.append(get_batch_card_details(batch.name)) - - batches = categorize_batches(batches) - return batches - - -def get_batch_card_details(batchname): - batch = frappe.db.get_value( - "LMS Batch", - batchname, - [ - "name", - "title", - "description", - "seat_count", - "paid_batch", - "amount", - "amount_usd", - "currency", - "start_date", - "end_date", - "start_time", - "end_time", - "timezone", - "published", - "category", - ], - as_dict=True, - ) - - batch.instructors = get_instructors(batchname) - students_count = frappe.db.count("Batch Student", {"parent": batchname}) - - if batch.seat_count: - batch.seats_left = batch.seat_count - students_count - - if batch.paid_batch and batch.start_date >= getdate(): - batch.amount, batch.currency = check_multicurrency( - batch.amount, batch.currency, None, batch.amount_usd - ) - batch.price = fmt_money(batch.amount, 0, batch.currency) - - return batch - - @frappe.whitelist(allow_guest=True) def get_batch_details(batch): batch_details = frappe.db.get_value(