From 881c3d943ae1508500d87f5a4137560030af443e Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Mon, 18 Dec 2023 20:06:43 +0530
Subject: [PATCH 1/6] fix: evaluation fields
---
.../lms_certificate_evaluation.json | 7 ++++---
.../lms_certificate_evaluation.py | 7 ++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.json b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.json
index 998ce8bc..d698fe17 100644
--- a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.json
+++ b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.json
@@ -47,12 +47,13 @@
"fieldtype": "Rating",
"in_list_view": 1,
"label": "Rating",
- "reqd": 1
+ "mandatory_depends_on": "eval:doc.status != 'Pending' && doc.status != 'In Progress'"
},
{
"fieldname": "summary",
"fieldtype": "Small Text",
- "label": "Summary"
+ "label": "Summary",
+ "mandatory_depends_on": "eval:doc.status != 'Pending' && doc.status != 'In Progress'"
},
{
"fieldname": "date",
@@ -106,7 +107,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-09-26 19:44:43.594892",
+ "modified": "2023-12-18 20:03:27.040073",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Certificate Evaluation",
diff --git a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
index 82105486..7485d135 100644
--- a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
+++ b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
@@ -8,7 +8,12 @@ from lms.lms.utils import has_course_moderator_role
class LMSCertificateEvaluation(Document):
- pass
+ def validate(self):
+ self.validate_rating()
+
+ def validate_rating(self):
+ if self.status not in ["Pending", "In Progress"] and self.rating == 0:
+ frappe.throw("Rating cannot be 0")
def has_website_permission(doc, ptype, user, verbose=False):
From 6604866342413d8846fa8ef8c4303549ebad1764 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Tue, 19 Dec 2023 10:51:36 +0530
Subject: [PATCH 2/6] fix: assignment issue
---
.../lms_assignment_submission/lms_assignment_submission.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
index a58f2207..c35f5b49 100644
--- a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
+++ b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
@@ -4,7 +4,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
-from frappe.utils import validate_url
+from frappe.utils import validate_url, validate_email_address
from frappe.email.doctype.email_template.email_template import get_email_template
@@ -43,6 +43,9 @@ class LMSAssignmentSubmission(Document):
}
moderators = frappe.get_all("Has Role", {"role": "Moderator"}, pluck="parent")
+ for moderator in moderators:
+ if not validate_email_address(moderator):
+ moderators.remove(moderator)
if custom_template:
email_template = get_email_template(custom_template, args)
From 00b0a20c83e5a077228bbe9896806fcfb89ae6f5 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Tue, 19 Dec 2023 10:54:56 +0530
Subject: [PATCH 3/6] fix: translations
---
.../lms_certificate_evaluation/lms_certificate_evaluation.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
index 7485d135..2bf59b74 100644
--- a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
+++ b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py
@@ -2,6 +2,7 @@
# For license information, please see license.txt
import frappe
+from frappe import _
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
from lms.lms.utils import has_course_moderator_role
@@ -13,7 +14,7 @@ class LMSCertificateEvaluation(Document):
def validate_rating(self):
if self.status not in ["Pending", "In Progress"] and self.rating == 0:
- frappe.throw("Rating cannot be 0")
+ frappe.throw(_("Rating cannot be 0"))
def has_website_permission(doc, ptype, user, verbose=False):
From b0d0b41502621fcf110ea287a99d0c3712953a5e Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Wed, 20 Dec 2023 11:37:54 +0530
Subject: [PATCH 4/6] fix: batch meta image saving
---
lms/lms/doctype/lms_batch/lms_batch.py | 2 +-
lms/www/batches/batch.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py
index 857df297..e2e23555 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.py
+++ b/lms/lms/doctype/lms_batch/lms_batch.py
@@ -274,7 +274,7 @@ def create_batch(
"description": description,
"batch_details": batch_details,
"batch_details_raw": batch_details_raw,
- "image": meta_image,
+ "meta_image": meta_image,
"seat_count": seat_count,
"start_time": start_time,
"end_time": end_time,
diff --git a/lms/www/batches/batch.py b/lms/www/batches/batch.py
index 666658cc..c03e9e9f 100644
--- a/lms/www/batches/batch.py
+++ b/lms/www/batches/batch.py
@@ -44,6 +44,7 @@ def get_context(context):
"published",
"allow_future",
"evaluation_end_date",
+ "meta_image",
],
as_dict=True,
)
@@ -156,7 +157,6 @@ def get_class_course_details(batch_courses):
"image",
"upcoming",
"short_introduction",
- "image",
"paid_course",
"course_price",
"enable_certification",
From 7a9d6325d5bd4281af2776e8740b404591491497 Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Wed, 20 Dec 2023 11:49:32 +0530
Subject: [PATCH 5/6] fix: copy of enrollment email
---
lms/templates/emails/batch_confirmation.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lms/templates/emails/batch_confirmation.html b/lms/templates/emails/batch_confirmation.html
index 4e9ad30a..ce8850a2 100644
--- a/lms/templates/emails/batch_confirmation.html
+++ b/lms/templates/emails/batch_confirmation.html
@@ -3,7 +3,7 @@
- {{ _("I am pleased to inform you that your enrollment for the upcoming training batch has been successfully processed. Congratulations!") }}
+ {{ _("We are pleased to inform you that you have been enrolled in our upcoming batch. Congratulations!") }}
From 13536b8bad9161017301cb9bdf2d21ccbe2d212f Mon Sep 17 00:00:00 2001
From: Jannat Patel
Date: Thu, 21 Dec 2023 12:28:11 +0530
Subject: [PATCH 6/6] feat: usd pricing
---
lms/lms/doctype/lms_batch/lms_batch.json | 10 +++++++++-
lms/lms/doctype/lms_batch/lms_batch.py | 2 ++
lms/lms/doctype/lms_course/lms_course.json | 18 ++++++++++++++---
lms/lms/utils.py | 23 ++++++++++++++--------
lms/public/js/common_functions.js | 9 +++++++++
lms/www/batches/batch_details.py | 6 +++++-
lms/www/batches/index.py | 5 ++++-
lms/www/billing/billing.py | 7 ++++---
lms/www/courses/course.py | 3 ++-
lms/www/courses/index.py | 3 ++-
10 files changed, 67 insertions(+), 19 deletions(-)
diff --git a/lms/lms/doctype/lms_batch/lms_batch.json b/lms/lms/doctype/lms_batch/lms_batch.json
index fd9f7793..b05ee563 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.json
+++ b/lms/lms/doctype/lms_batch/lms_batch.json
@@ -46,6 +46,7 @@
"column_break_iens",
"amount",
"currency",
+ "amount_usd",
"customisations_tab",
"section_break_ubxi",
"custom_component",
@@ -285,11 +286,18 @@
"fieldname": "evaluation_end_date",
"fieldtype": "Date",
"label": "Evaluation End Date"
+ },
+ {
+ "depends_on": "paid_batch",
+ "description": "If you set an amount here, then the USD equivalent setting will not get applied.",
+ "fieldname": "amount_usd",
+ "fieldtype": "Currency",
+ "label": "Amount (USD)"
}
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-11-29 12:06:58.776479",
+ "modified": "2023-12-21 12:27:16.849362",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch",
diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py
index e2e23555..eb0065ab 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.py
+++ b/lms/lms/doctype/lms_batch/lms_batch.py
@@ -256,6 +256,7 @@ def create_batch(
paid_batch=0,
amount=0,
currency=None,
+ amount_usd=0,
name=None,
published=0,
evaluation_end_date=None,
@@ -283,6 +284,7 @@ def create_batch(
"paid_batch": paid_batch,
"amount": amount,
"currency": currency,
+ "amount_usd": amount_usd,
"published": published,
"evaluation_end_date": evaluation_end_date,
}
diff --git a/lms/lms/doctype/lms_course/lms_course.json b/lms/lms/doctype/lms_course/lms_course.json
index 74f7474a..f26e382d 100644
--- a/lms/lms/doctype/lms_course/lms_course.json
+++ b/lms/lms/doctype/lms_course/lms_course.json
@@ -34,8 +34,10 @@
"related_courses",
"pricing_section",
"paid_course",
- "currency",
+ "column_break_acoj",
"course_price",
+ "currency",
+ "amount_usd",
"certification_section",
"enable_certification",
"expiry",
@@ -222,12 +224,22 @@
"fieldname": "course_price",
"fieldtype": "Currency",
"label": "Course Price",
- "option": "currency",
"mandatory_depends_on": "paid_course"
},
{
"fieldname": "column_break_rxww",
"fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "column_break_acoj",
+ "fieldtype": "Column Break"
+ },
+ {
+ "depends_on": "paid_course",
+ "description": "If you set an amount here, then the USD equivalent setting will not get applied.",
+ "fieldname": "amount_usd",
+ "fieldtype": "Currency",
+ "label": "Amount (USD)"
}
],
"is_published_field": "published",
@@ -254,7 +266,7 @@
}
],
"make_attachments_public": 1,
- "modified": "2023-08-28 11:09:11.945066",
+ "modified": "2023-12-21 12:27:32.559901",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 3f5ec9f5..f271811e 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -906,8 +906,9 @@ def get_payment_options(doctype, docname, phone, country):
validate_phone_number(phone, True)
details = get_details(doctype, docname)
+
details.amount, details.currency = check_multicurrency(
- details.amount, details.currency, country
+ details.amount, details.currency, country, details.amount_usd
)
if details.currency == "INR":
details.amount, details.gst_applied = apply_gst(details.amount, country)
@@ -931,16 +932,20 @@ def get_payment_options(doctype, docname, phone, country):
return options
-def check_multicurrency(amount, currency, country=None):
+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"
)
- apply_rounding = frappe.db.get_single_value("LMS Settings", "apply_rounding")
- country = country or frappe.db.get_value(
- "Address", {"email_id": frappe.session.user}, "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")
)
+ if amount_usd and country not in exception_country:
+ return amount_usd, "USD"
+
if not show_usd_equivalent or currency == "USD":
return amount, currency
@@ -951,6 +956,7 @@ def check_multicurrency(amount, currency, country=None):
amount = amount * exchange_rate
currency = "USD"
+ apply_rounding = frappe.db.get_single_value("LMS Settings", "apply_rounding")
if apply_rounding and amount % 100 != 0:
amount = amount + 100 - amount % 100
@@ -976,7 +982,7 @@ def get_details(doctype, docname):
details = frappe.db.get_value(
"LMS Course",
docname,
- ["name", "title", "paid_course", "currency", "course_price as amount"],
+ ["name", "title", "paid_course", "currency", "course_price as amount", "amount_usd"],
as_dict=True,
)
if not details.paid_course:
@@ -985,7 +991,7 @@ def get_details(doctype, docname):
details = frappe.db.get_value(
"LMS Batch",
docname,
- ["name", "title", "paid_batch", "currency", "amount"],
+ ["name", "title", "paid_batch", "currency", "amount", "amount_usd"],
as_dict=True,
)
if not details.paid_batch:
@@ -1097,9 +1103,10 @@ def get_payment_details(doctype, docname, address):
amount_field = "course_price" if doctype == "LMS Course" else "amount"
amount = frappe.db.get_value(doctype, docname, amount_field)
currency = frappe.db.get_value(doctype, docname, "currency")
+ amount_usd = frappe.db.get_value(doctype, docname, "amount_usd")
amount_with_gst = 0
- amount, currency = check_multicurrency(amount, currency)
+ amount, currency = check_multicurrency(amount, currency, None, amount_usd)
if currency == "INR" and address.country == "India":
amount_with_gst, gst_applied = apply_gst(amount, address.country)
diff --git a/lms/public/js/common_functions.js b/lms/public/js/common_functions.js
index 48559002..43306240 100644
--- a/lms/public/js/common_functions.js
+++ b/lms/public/js/common_functions.js
@@ -392,6 +392,15 @@ const open_batch_dialog = () => {
depends_on: "paid_batch",
only_select: 1,
},
+ {
+ fieldtype: "Currency",
+ label: __("Amount (USD)"),
+ fieldname: "amount_usd",
+ depends_on: "paid_batch",
+ description: __(
+ "If you set an amount here, then the USD equivalent setting will not get applied."
+ ),
+ },
],
primary_action_label: __("Save"),
primary_action: (values) => {
diff --git a/lms/www/batches/batch_details.py b/lms/www/batches/batch_details.py
index 875dd887..fdeb035b 100644
--- a/lms/www/batches/batch_details.py
+++ b/lms/www/batches/batch_details.py
@@ -34,13 +34,17 @@ def get_context(context):
"meta_image",
"batch_details_raw",
"evaluation_end_date",
+ "amount_usd",
],
as_dict=1,
)
if context.batch_info.amount and context.batch_info.currency:
amount, currency = check_multicurrency(
- context.batch_info.amount, context.batch_info.currency
+ context.batch_info.amount,
+ context.batch_info.currency,
+ None,
+ context.batch_info.amount_usd,
)
context.batch_info.amount = amount
context.batch_info.currency = currency
diff --git a/lms/www/batches/index.py b/lms/www/batches/index.py
index 127fe5f2..20d89bb6 100644
--- a/lms/www/batches/index.py
+++ b/lms/www/batches/index.py
@@ -26,6 +26,7 @@ def get_context(context):
"currency",
"seat_count",
"published",
+ "amount_usd",
],
order_by="start_date",
)
@@ -36,7 +37,9 @@ def get_context(context):
batch.course_count = frappe.db.count("Batch Course", {"parent": batch.name})
if batch.amount and batch.currency:
- amount, currency = check_multicurrency(batch.amount, batch.currency)
+ amount, currency = check_multicurrency(
+ batch.amount, batch.currency, None, batch.amount_usd
+ )
batch.amount = amount
batch.currency = currency
diff --git a/lms/www/billing/billing.py b/lms/www/billing/billing.py
index d91013de..7742f730 100644
--- a/lms/www/billing/billing.py
+++ b/lms/www/billing/billing.py
@@ -27,7 +27,7 @@ def get_context(context):
)
context.amount, context.currency = check_multicurrency(
- context.amount, context.currency
+ context.amount, context.currency, None, context.amount_usd
)
context.address = get_address()
@@ -65,7 +65,7 @@ def get_billing_details(context):
details = frappe.db.get_value(
"LMS Course",
context.docname,
- ["title", "name", "paid_course", "course_price as amount", "currency"],
+ ["title", "name", "paid_course", "course_price as amount", "currency", "amount_usd"],
as_dict=True,
)
@@ -76,7 +76,7 @@ def get_billing_details(context):
details = frappe.db.get_value(
"LMS Batch",
context.docname,
- ["title", "name", "paid_batch", "amount", "currency"],
+ ["title", "name", "paid_batch", "amount", "currency", "amount_usd"],
as_dict=True,
)
@@ -88,6 +88,7 @@ def get_billing_details(context):
context.title = details.title
context.amount = details.amount
context.currency = details.currency
+ context.amount_usd = details.amount_usd
def get_address():
diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py
index 60056698..59314a6d 100644
--- a/lms/www/courses/course.py
+++ b/lms/www/courses/course.py
@@ -56,6 +56,7 @@ def set_course_context(context, course_name):
"paid_course",
"course_price",
"currency",
+ "amount_usd",
"enable_certification",
"grant_certificate_after",
],
@@ -64,7 +65,7 @@ def set_course_context(context, course_name):
if course.course_price:
course.course_price, course.currency = check_multicurrency(
- course.course_price, course.currency
+ course.course_price, course.currency, None, course.amount_usd
)
if frappe.form_dict.get("edit"):
diff --git a/lms/www/courses/index.py b/lms/www/courses/index.py
index 7df2a960..dfee2260 100644
--- a/lms/www/courses/index.py
+++ b/lms/www/courses/index.py
@@ -61,6 +61,7 @@ def get_courses():
"course_price",
"currency",
"creation",
+ "amount_usd",
],
)
@@ -72,7 +73,7 @@ def get_courses():
if course.course_price:
course.course_price, course.currency = check_multicurrency(
- course.course_price, course.currency
+ course.course_price, course.currency, None, course.amount_usd
)
course.avg_rating = get_average_rating(course.name) or 0