From 0692aceda406e0fef28f6a7c8a85afc952cfb7cd Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 19 Mar 2025 10:45:47 +0530 Subject: [PATCH] fix: don't allow billing page access if batch is sold out --- frontend/src/pages/Billing.vue | 2 -- lms/lms/api.py | 6 ++++++ lms/lms/doctype/lms_payment/lms_payment.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Billing.vue b/frontend/src/pages/Billing.vue index ca74fbdd..7c4242d6 100644 --- a/frontend/src/pages/Billing.vue +++ b/frontend/src/pages/Billing.vue @@ -245,12 +245,10 @@ const paymentLink = createResource({ }) const generatePaymentLink = () => { - console.log('called') paymentLink.submit( {}, { validate() { - console.log('validation start') if (!billingDetails.source) { return __('Please let us know where you heard about us from.') } diff --git a/lms/lms/api.py b/lms/lms/api.py index 119fb845..83af8015 100644 --- a/lms/lms/api.py +++ b/lms/lms/api.py @@ -229,6 +229,12 @@ def validate_billing_access(billing_type, name): access = False message = _("You are already enrolled for this batch.") + seat_count = frappe.get_cached_value("LMS Batch", name, "seat_count") + number_of_students = frappe.db.count("LMS Batch Enrollment", {"batch": name}) + if seat_count <= number_of_students: + access = False + message = _("Batch is sold out.") + elif access and billing_type == "certificate": purchased_certificate = frappe.db.exists( "LMS Enrollment", diff --git a/lms/lms/doctype/lms_payment/lms_payment.py b/lms/lms/doctype/lms_payment/lms_payment.py index 1378f4e3..3d28c7f0 100644 --- a/lms/lms/doctype/lms_payment/lms_payment.py +++ b/lms/lms/doctype/lms_payment/lms_payment.py @@ -35,6 +35,9 @@ def send_payment_reminder(): for payment in incomplete_payments: if has_paid_later(payment): continue + + if is_batch_sold_out(payment): + continue send_mail(payment) @@ -51,6 +54,16 @@ def has_paid_later(payment): ) +def is_batch_sold_out(payment): + if payment.payment_for_document_type == "LMS Batch": + seat_count = frappe.get_cached_value("LMS Batch", payment.payment_for_document, "seat_count") + number_of_students = frappe.db.count("LMS Batch Enrollment", {"batch": payment.payment_for_document}) + + if seat_count <= number_of_students: + return True + + return False + def send_mail(payment): subject = _("Complete Your Enrollment - Don't miss out!") template = "payment_reminder"