fix: don't allow billing page access if batch is sold out

This commit is contained in:
Jannat Patel
2025-03-19 10:45:47 +05:30
parent e94a689f83
commit 0692aceda4
3 changed files with 19 additions and 2 deletions

View File

@@ -245,12 +245,10 @@ const paymentLink = createResource({
}) })
const generatePaymentLink = () => { const generatePaymentLink = () => {
console.log('called')
paymentLink.submit( paymentLink.submit(
{}, {},
{ {
validate() { validate() {
console.log('validation start')
if (!billingDetails.source) { if (!billingDetails.source) {
return __('Please let us know where you heard about us from.') return __('Please let us know where you heard about us from.')
} }

View File

@@ -229,6 +229,12 @@ def validate_billing_access(billing_type, name):
access = False access = False
message = _("You are already enrolled for this batch.") 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": elif access and billing_type == "certificate":
purchased_certificate = frappe.db.exists( purchased_certificate = frappe.db.exists(
"LMS Enrollment", "LMS Enrollment",

View File

@@ -35,6 +35,9 @@ def send_payment_reminder():
for payment in incomplete_payments: for payment in incomplete_payments:
if has_paid_later(payment): if has_paid_later(payment):
continue continue
if is_batch_sold_out(payment):
continue
send_mail(payment) 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): def send_mail(payment):
subject = _("Complete Your Enrollment - Don't miss out!") subject = _("Complete Your Enrollment - Don't miss out!")
template = "payment_reminder" template = "payment_reminder"