diff --git a/lms/www/batches/index.py b/lms/www/batches/index.py index e16105bf..6112fdc2 100644 --- a/lms/www/batches/index.py +++ b/lms/www/batches/index.py @@ -48,7 +48,7 @@ def get_context(context): else: upcoming_batches.append(batch) - context.past_batches = sorted(past_batches, key=lambda d: d.start_date) + context.past_batches = sorted(past_batches, key=lambda d: d.start_date, reverse=True) context.upcoming_batches = sorted(upcoming_batches, key=lambda d: d.start_date) context.private_batches = sorted(private_batches, key=lambda d: d.start_date) @@ -83,5 +83,6 @@ def get_context(context): batchinfo.seats_left = batchinfo.seat_count - batchinfo.student_count my_batches_info.append(batchinfo) + my_batches_info = sorted(my_batches_info, key=lambda d: d.start_date, reverse=True) context.my_batches = my_batches_info diff --git a/lms/www/billing/billing.js b/lms/www/billing/billing.js index 3be9b310..1c891b0e 100644 --- a/lms/www/billing/billing.js +++ b/lms/www/billing/billing.js @@ -106,6 +106,7 @@ const setup_billing = () => { const generate_payment_link = (e) => { let new_address = this.billing.get_values(); + validate_address(new_address); let doctype = $(e.currentTarget).attr("data-doctype"); let docname = decodeURIComponent($(e.currentTarget).attr("data-name")); @@ -174,8 +175,10 @@ const change_currency = () => { if (current_price != data.message) { update_price(data.message); } - if (!data.message.includes("INR")) { - $("#gst-message").addClass("hide"); + if (data.message.includes("INR")) { + $("#gst-message").removeClass("hide").addClass("show"); + } else { + $("#gst-message").removeClass("show").addClass("hide"); } }, }); @@ -188,3 +191,48 @@ const update_price = (price) => { indicator: "yellow", }); }; + +const validate_address = (billing_address) => { + if (billing_address.country == "India" && !billing_address.state) + frappe.throw(__("State is mandatory.")); + + const states = [ + "Andhra Pradesh", + "Arunachal Pradesh", + "Assam", + "Bihar", + "Chhattisgarh", + "Goa", + "Gujarat", + "Haryana", + "Himachal Pradesh", + "Jharkhand", + "Karnataka", + "Kerala", + "Madhya Pradesh", + "Maharashtra", + "Manipur", + "Meghalaya", + "Mizoram", + "Nagaland", + "Odisha", + "Punjab", + "Rajasthan", + "Sikkim", + "Tamil Nadu", + "Telangana", + "Tripura", + "Uttar Pradesh", + "Uttarakhand", + "West Bengal", + ]; + if ( + billing_address.country == "India" && + !states.includes(billing_address.state) + ) + frappe.throw( + __( + "Please enter a valid state with correct spelling and the first letter capitalized." + ) + ); +}; diff --git a/lms/www/billing/billing.py b/lms/www/billing/billing.py index ad1d45d3..d91013de 100644 --- a/lms/www/billing/billing.py +++ b/lms/www/billing/billing.py @@ -15,6 +15,13 @@ def get_context(context): validate_access(doctype, docname, module) get_billing_details(context) + context.original_currency = context.currency + context.original_amount = ( + apply_gst(context.amount, None)[0] + if context.original_currency == "INR" + else context.amount + ) + context.exception_country = frappe.get_all( "Payment Country", filters={"parent": "LMS Settings"}, pluck="country" ) @@ -27,9 +34,6 @@ def get_context(context): if context.currency == "INR": context.amount, context.gst_applied = apply_gst(context.amount, None) - context.original_amount = context.amount - context.original_currency = context.currency - def validate_access(doctype, docname, module): if frappe.session.user == "Guest":