diff --git a/frontend/src/pages/Batches.vue b/frontend/src/pages/Batches.vue index 935ddbf08..0023dd5fc 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 8aa3a1ff7..244115538 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_batches(): - 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( @@ -1902,3 +1848,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