feat: multicurrency

This commit is contained in:
Jannat Patel
2023-09-12 12:13:41 +05:30
parent 04501143ec
commit f137f8e048
3 changed files with 39 additions and 18 deletions

View File

@@ -13,8 +13,9 @@
"billing_name", "billing_name",
"payment_received", "payment_received",
"payment_details_section", "payment_details_section",
"amount",
"currency", "currency",
"amount",
"amount_with_gst",
"column_break_yxpl", "column_break_yxpl",
"order_id", "order_id",
"payment_id", "payment_id",
@@ -39,7 +40,8 @@
"fieldname": "amount", "fieldname": "amount",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Amount" "label": "Amount",
"options": "currency"
}, },
{ {
"fieldname": "currency", "fieldname": "currency",
@@ -107,11 +109,17 @@
"label": "Member", "label": "Member",
"options": "User", "options": "User",
"reqd": 1 "reqd": 1
},
{
"depends_on": "eval:doc.currency == \"INR\";",
"fieldname": "amount_with_gst",
"fieldtype": "Currency",
"label": "Amount with GST"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2023-08-24 22:08:12.294960", "modified": "2023-09-12 10:40:22.721371",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Payment", "name": "LMS Payment",

View File

@@ -838,8 +838,11 @@ def get_payment_options(doctype, docname, phone, country):
validate_phone_number(phone, True) validate_phone_number(phone, True)
details = get_details(doctype, docname) details = get_details(doctype, docname)
details.amount, details.currency = check_multicurrency(details) details.amount, details.currency = check_multicurrency(
details.amount, details.gst_applied = apply_gst(details, country) details.amount, details.currency
)
if details.currency == "INR":
details.amount, details.gst_applied = apply_gst(details.amount, country)
client = get_client() client = get_client()
order = create_order(client, details.amount, details.currency) order = create_order(client, details.amount, details.currency)
@@ -862,18 +865,17 @@ def get_payment_options(doctype, docname, phone, country):
def check_multicurrency(amount, currency): def check_multicurrency(amount, currency):
show_usd_equivalent = frappe.db.get_single_value("LMS Settings", "show_usd_equivalent") show_usd_equivalent = frappe.db.get_single_value("LMS Settings", "show_usd_equivalent")
exception_country = frappe.db.get_single_value("LMS Settings", "exception_country") exception_country = frappe.get_all(
"Payment Country", filters={"parent": "LMS Settings"}, pluck="country"
)
apply_rounding = frappe.db.get_single_value("LMS Settings", "apply_rounding") apply_rounding = frappe.db.get_single_value("LMS Settings", "apply_rounding")
country = frappe.db.get_value("User", frappe.session.user, "country") country = frappe.db.get_value("User", frappe.session.user, "country")
if not show_usd_equivalent: if not show_usd_equivalent or currency == "USD":
return return amount, currency
if currency == "USD":
return
if exception_country and country in exception_country: if exception_country and country in exception_country:
return return amount, currency
exchange_rate = get_current_exchange_rate(currency, "USD") exchange_rate = get_current_exchange_rate(currency, "USD")
amount = amount * exchange_rate amount = amount * exchange_rate
@@ -885,10 +887,13 @@ def check_multicurrency(amount, currency):
return amount, currency return amount, currency
def apply_gst(amount, country): def apply_gst(amount, country=None):
gst_applied = False gst_applied = False
apply_gst = frappe.db.get_single_value("LMS Settings", "apply_gst") apply_gst = frappe.db.get_single_value("LMS Settings", "apply_gst")
if not country:
country = frappe.db.get_value("User", frappe.session.user, "country")
if apply_gst and country == "India": if apply_gst and country == "India":
gst_applied = True gst_applied = True
amount = amount * 1.18 amount = amount * 1.18
@@ -998,6 +1003,7 @@ def record_payment(address, response, client, doctype, docname):
"payment_id": response["razorpay_payment_id"], "payment_id": response["razorpay_payment_id"],
"amount": payment_details["amount"], "amount": payment_details["amount"],
"currency": payment_details["currency"], "currency": payment_details["currency"],
"amount_with_gst": payment_details["amount_with_gst"],
"gstin": address.gstin, "gstin": address.gstin,
"pan": address.pan, "pan": address.pan,
} }
@@ -1010,13 +1016,16 @@ def get_payment_details(doctype, docname, address):
amount_field = "course_price" if doctype == "LMS Course" else "amount" amount_field = "course_price" if doctype == "LMS Course" else "amount"
amount = frappe.db.get_value(doctype, docname, amount_field) amount = frappe.db.get_value(doctype, docname, amount_field)
currency = frappe.db.get_value(doctype, docname, "currency") currency = frappe.db.get_value(doctype, docname, "currency")
apply_gst = frappe.db.get_single_value("LMS Settings", "apply_gst") amount_with_gst = 0
if apply_gst and address.country == "India":
amount = amount * 1.18 amount, currency = check_multicurrency(amount, currency)
if currency == "INR" and address.country == "India":
amount_with_gst, gst_applied = apply_gst(amount, address.country)
return { return {
"amount": amount, "amount": amount,
"currency": currency, "currency": currency,
"amount_with_gst": amount_with_gst,
} }

View File

@@ -14,8 +14,12 @@ def get_context(context):
validate_access(doctype, docname, module) validate_access(doctype, docname, module)
get_billing_details(context) get_billing_details(context)
check_multicurrency(context) context.amount, context.currency = check_multicurrency(
apply_gst(context) context.amount, context.currency
)
if context.currency == "INR":
context.amount, context.gst_applied = apply_gst(context.amount, None)
def validate_access(doctype, docname, module): def validate_access(doctype, docname, module):