diff --git a/frontend/src/pages/Lesson.vue b/frontend/src/pages/Lesson.vue
index 94b5dd4d..3b15b4da 100644
--- a/frontend/src/pages/Lesson.vue
+++ b/frontend/src/pages/Lesson.vue
@@ -227,11 +227,6 @@ const lesson = createResource({
},
auto: true,
onSuccess(data) {
- if (data.membership)
- current_lesson.submit({
- name: data.membership.name,
- lesson_name: data.name,
- })
markProgress(data)
if (data.content) editor = renderEditor('editor', data.content)
@@ -260,18 +255,6 @@ const markProgress = (data) => {
if (user.data && !data.progress) progress.submit()
}
-const current_lesson = createResource({
- url: 'frappe.client.set_value',
- makeParams(values) {
- return {
- doctype: 'LMS Enrollment',
- name: values.name,
- fieldname: 'current_lesson',
- value: values.lesson_name,
- }
- },
-})
-
const progress = createResource({
url: 'lms.lms.doctype.course_lesson.course_lesson.save_progress',
makeParams() {
diff --git a/frontend/src/router.js b/frontend/src/router.js
index 4c207c6e..3b53ce19 100644
--- a/frontend/src/router.js
+++ b/frontend/src/router.js
@@ -154,7 +154,7 @@ router.beforeEach(async (to, from, next) => {
try {
if (isLoggedIn) {
- await userResource.reload()
+ await userResource.promise
}
if (
isLoggedIn &&
@@ -163,7 +163,7 @@ router.beforeEach(async (to, from, next) => {
to.name == 'Notifications' ||
to.name == 'Badge')
) {
- await allUsers.reload()
+ await allUsers.promise
}
} catch (error) {
isLoggedIn = false
diff --git a/frontend/src/stores/user.js b/frontend/src/stores/user.js
index 08232703..1c1c6c02 100644
--- a/frontend/src/stores/user.js
+++ b/frontend/src/stores/user.js
@@ -9,6 +9,7 @@ export const usersStore = defineStore('lms-users', () => {
router.push('/login')
}
},
+ auto: true,
})
const allUsers = createResource({
diff --git a/lms/lms/doctype/course_lesson/course_lesson.py b/lms/lms/doctype/course_lesson/course_lesson.py
index b4007dd3..955b08ec 100644
--- a/lms/lms/doctype/course_lesson/course_lesson.py
+++ b/lms/lms/doctype/course_lesson/course_lesson.py
@@ -95,6 +95,8 @@ def save_progress(lesson, course):
if not membership:
return 0
+ frappe.db.set_value("LMS Enrollment", membership, "current_lesson", lesson)
+
quiz_completed = get_quiz_progress(lesson)
if not quiz_completed:
return 0
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 07c8f9f5..378e6708 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -1018,31 +1018,42 @@ def get_payment_options(doctype, docname, phone, country):
def check_multicurrency(amount, currency, country=None, amount_usd=None):
- show_usd_equivalent = frappe.db.get_single_value("LMS Settings", "show_usd_equivalent")
- exception_country = frappe.get_all(
- "Payment Country", filters={"parent": "LMS Settings"}, pluck="country"
- )
- country = (
- country
- or frappe.db.get_value("Address", {"email_id": frappe.session.user}, "country")
- or frappe.db.get_value("User", frappe.session.user, "country")
- or get_country_code()
- )
+ settings = frappe.get_single("LMS Settings")
+ show_usd_equivalent = settings.show_usd_equivalent
- if amount_usd and country and country not in exception_country:
- return amount_usd, "USD"
+ # Countries for which currency should not be converted
+ exception_country = settings.exception_country
+ exception_country = [country.country for country in exception_country]
- if not show_usd_equivalent or currency == "USD":
- return amount, currency
+ # Get users country
+ if not country:
+ country = frappe.db.get_value("Address", {"email_id": frappe.session.user}, "country")
+ if not country:
+ country = frappe.db.get_value("User", frappe.session.user, "country")
+
+ if not country:
+ country = get_country_code()
+
+ # If the country is the one for which conversion is not needed then return as is
if not country or (exception_country and country in exception_country):
return amount, currency
+ # If conversion is disabled from settings or the currency is already USD then return as is
+ if not show_usd_equivalent or currency == "USD":
+ return amount, currency
+
+ # If Explicit USD price is given then return that without conversion
+ if amount_usd and country and country not in exception_country:
+ return amount_usd, "USD"
+
+ # Conversion logic starts here. Exchange rate is fetched and amount is converted.
exchange_rate = get_current_exchange_rate(currency, "USD")
amount = amount * exchange_rate
currency = "USD"
- apply_rounding = frappe.db.get_single_value("LMS Settings", "apply_rounding")
+ # Check if the amount should be rounded and then apply rounding
+ apply_rounding = settings.apply_rounding
if apply_rounding and amount % 100 != 0:
amount = amount + 100 - amount % 100
@@ -1466,10 +1477,13 @@ def get_neighbour_lesson(course, chapter, lesson):
@frappe.whitelist(allow_guest=True)
def get_batches():
batches = []
- batch_list = frappe.get_all("LMS Batch", pluck="name")
+ filters = {}
+ if frappe.session.user == "Guest":
+ filters.update({"start_date": [">=", getdate()], "published": 1})
+ batch_list = frappe.get_all("LMS Batch", filters)
for batch in batch_list:
- batches.append(get_batch_details(batch))
+ batches.append(get_batch_details(batch.name))
batches = categorize_batches(batches)
return batches
@@ -1508,18 +1522,14 @@ def get_batch_details(batch):
batch_details.students = frappe.get_all(
"Batch Student", {"parent": batch}, pluck="student"
)
- if batch_details.paid_batch:
+ if batch_details.paid_batch and batch_details.start_date >= getdate():
batch_details.amount, batch_details.currency = check_multicurrency(
batch_details.amount, batch_details.currency, None, batch_details.amount_usd
)
batch_details.price = fmt_money(batch_details.amount, 0, batch_details.currency)
if batch_details.seat_count:
- students_enrolled = frappe.db.count(
- "Batch Student",
- {"parent": batch},
- )
- batch_details.seats_left = batch_details.seat_count - students_enrolled
+ batch_details.seats_left = batch_details.seat_count - len(batch_details.students)
return batch_details