fix: check country from ip for multicurrency
This commit is contained in:
@@ -941,9 +941,10 @@ def check_multicurrency(amount, currency, country=None, amount_usd=None):
|
|||||||
country
|
country
|
||||||
or frappe.db.get_value("Address", {"email_id": frappe.session.user}, "country")
|
or frappe.db.get_value("Address", {"email_id": frappe.session.user}, "country")
|
||||||
or frappe.db.get_value("User", 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"
|
return amount_usd, "USD"
|
||||||
|
|
||||||
if not show_usd_equivalent or currency == "USD":
|
if not show_usd_equivalent or currency == "USD":
|
||||||
@@ -1155,3 +1156,16 @@ def change_currency(amount, currency, country=None):
|
|||||||
amount = cint(amount)
|
amount = cint(amount)
|
||||||
amount, currency = check_multicurrency(amount, currency, country)
|
amount, currency = check_multicurrency(amount, currency, country)
|
||||||
return fmt_money(amount, 0, currency)
|
return fmt_money(amount, 0, currency)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from frappe import _
|
|||||||
from frappe.core.doctype.user.user import User
|
from frappe.core.doctype.user.user import User
|
||||||
from frappe.utils import cint, escape_html, random_string
|
from frappe.utils import cint, escape_html, random_string
|
||||||
from frappe.website.utils import is_signup_disabled
|
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.website.utils import cleanup_page_name
|
||||||
from frappe.model.naming import append_number_if_name_exists
|
from frappe.model.naming import append_number_if_name_exists
|
||||||
from lms.widgets import Widgets
|
from lms.widgets import Widgets
|
||||||
@@ -260,19 +260,6 @@ def set_country_from_ip(login_manager=None, user=None):
|
|||||||
return
|
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):
|
def on_session_creation(login_manager):
|
||||||
if frappe.db.get_single_value(
|
if frappe.db.get_single_value(
|
||||||
"System Settings", "setup_complete"
|
"System Settings", "setup_complete"
|
||||||
|
|||||||
Reference in New Issue
Block a user