diff --git a/lms/lms/utils.py b/lms/lms/utils.py index a3c1f9ff..ab29d491 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -946,9 +946,10 @@ def check_multicurrency(amount, currency, country=None, amount_usd=None): 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() ) - if amount_usd and country not in exception_country: + if amount_usd and country and country not in exception_country: return amount_usd, "USD" if not show_usd_equivalent or currency == "USD": @@ -1387,3 +1388,16 @@ def categorize_batches(batches): "private": private, "enrolled": enrolled, } + + +def get_country_code(): + ip = frappe.local.request_ip + res = requests.get(f"http://ip-api.com/json/{ip}") + + try: + data = res.json() + if data.get("status") != "fail": + return frappe.db.get_value("Country", {"code": data.get("countryCode")}, "name") + except Exception: + pass + return diff --git a/lms/overrides/user.py b/lms/overrides/user.py index bfc1f49b..3643e473 100644 --- a/lms/overrides/user.py +++ b/lms/overrides/user.py @@ -5,7 +5,7 @@ from frappe import _ from frappe.core.doctype.user.user import User from frappe.utils import cint, escape_html, random_string from frappe.website.utils import is_signup_disabled -from lms.lms.utils import get_average_rating +from lms.lms.utils import get_average_rating, get_country_code from frappe.website.utils import cleanup_page_name from frappe.model.naming import append_number_if_name_exists from lms.widgets import Widgets @@ -260,19 +260,6 @@ def set_country_from_ip(login_manager=None, user=None): return -def get_country_code(): - ip = frappe.local.request_ip - res = requests.get(f"http://ip-api.com/json/{ip}") - - try: - data = res.json() - if data.get("status") != "fail": - return frappe.db.get_value("Country", {"code": data.get("countryCode")}, "name") - except Exception: - pass - return - - def on_session_creation(login_manager): if frappe.db.get_single_value( "System Settings", "setup_complete"