Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: usd pricing #710

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lms/lms/doctype/lms_batch/lms_batch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"column_break_iens",
"amount",
"currency",
"amount_usd",
"customisations_tab",
"section_break_ubxi",
"custom_component",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions lms/lms/doctype/lms_batch/lms_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down
18 changes: 15 additions & 3 deletions lms/lms/doctype/lms_course/lms_course.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"related_courses",
"pricing_section",
"paid_course",
"currency",
"column_break_acoj",
"course_price",
"currency",
"amount_usd",
"certification_section",
"enable_certification",
"expiry",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
23 changes: 15 additions & 8 deletions lms/lms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions lms/public/js/common_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 5 additions & 1 deletion lms/www/batches/batch_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lms/www/batches/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get_context(context):
"currency",
"seat_count",
"published",
"amount_usd",
],
order_by="start_date",
)
Expand All @@ -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

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

Expand All @@ -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,
)

Expand All @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion lms/www/courses/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def set_course_context(context, course_name):
"paid_course",
"course_price",
"currency",
"amount_usd",
"enable_certification",
"grant_certificate_after",
],
Expand All @@ -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"):
Expand Down
3 changes: 2 additions & 1 deletion lms/www/courses/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_courses():
"course_price",
"currency",
"creation",
"amount_usd",
],
)

Expand All @@ -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
Expand Down
Loading