fix: don't allow billing page access if batch is sold out
This commit is contained in:
@@ -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.')
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user