Skip to content

Commit

Permalink
fix: misc batch issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pateljannat committed Oct 27, 2023
1 parent c9ed8a4 commit a49871c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lms/www/batches/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
52 changes: 50 additions & 2 deletions lms/www/billing/billing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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");
}
},
});
Expand All @@ -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."
)
);
};
10 changes: 7 additions & 3 deletions lms/www/billing/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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":
Expand Down

0 comments on commit a49871c

Please sign in to comment.