fix: price update on country
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from frappe import _
|
||||
import frappe
|
||||
from frappe.utils import getdate, get_datetime
|
||||
from frappe.utils import getdate
|
||||
from lms.www.utils import get_assessments, is_student
|
||||
from lms.lms.utils import (
|
||||
has_course_moderator_role,
|
||||
@@ -52,14 +52,14 @@ def get_context(context):
|
||||
"Batch Course",
|
||||
{"parent": batch_name},
|
||||
["name", "course", "title"],
|
||||
order_by="creation desc",
|
||||
order_by="idx",
|
||||
)
|
||||
|
||||
batch_students = frappe.get_all(
|
||||
"Batch Student",
|
||||
{"parent": batch_name},
|
||||
["name", "student", "student_name", "username"],
|
||||
order_by="creation desc",
|
||||
order_by="idx",
|
||||
)
|
||||
|
||||
context.batch_courses = get_class_course_details(batch_courses)
|
||||
|
||||
@@ -164,24 +164,26 @@
|
||||
|
||||
|
||||
{% macro BatchDetails(batch_info) %}
|
||||
<div class="course-description-section w-50">
|
||||
<div class="mt-2">
|
||||
{{ batch_info.batch_details }}
|
||||
</div>
|
||||
<div class="batch-details">
|
||||
{{ batch_info.batch_details }}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro CourseList(courses) %}
|
||||
<div class="batch-course-list">
|
||||
{% if is_moderator %}
|
||||
<button class="btn btn-default btn-sm btn-add-course pull-right">
|
||||
{{ _("Add Courses") }}
|
||||
</button>
|
||||
{% endif %}
|
||||
<div class="page-title">
|
||||
{{ _("Courses") }}
|
||||
|
||||
<div class="flex align-center">
|
||||
<div class="page-title">
|
||||
{{ _("Courses") }}
|
||||
</div>
|
||||
{% if is_moderator %}
|
||||
<button class="btn btn-default btn-sm btn-add-course ml-4">
|
||||
{{ _("Add Course") }}
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if courses | length %}
|
||||
<div class="cards-parent mt-2">
|
||||
{% for course in courses %}
|
||||
|
||||
@@ -55,7 +55,7 @@ def get_context(context):
|
||||
"Batch Course",
|
||||
{"parent": batch_name},
|
||||
["name as batch_course", "course", "title", "evaluator"],
|
||||
order_by="creation desc",
|
||||
order_by="idx",
|
||||
)
|
||||
|
||||
for course in context.courses:
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
<div class="flex">
|
||||
<div class="field-label">
|
||||
{{ _("Total Price: ") }} {{ frappe.utils.fmt_money(amount, 2, currency) }}
|
||||
{{ _("Total Price: ") }}
|
||||
<span class="total-price">{{ frappe.utils.fmt_money(amount, 2, currency) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
{% if gst_applied %}
|
||||
@@ -64,4 +65,11 @@
|
||||
{%- block script %}
|
||||
{{ super() }}
|
||||
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
|
||||
<script>
|
||||
const address = {{ address if address else 0 }};
|
||||
const amount = {{ amount }};
|
||||
const currency = "{{ currency }}";
|
||||
const exception_country = {{ exception_country }};
|
||||
const original_price_formatted = "{{ frappe.utils.fmt_money(original_amount, 0, original_currency) }}"
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -18,23 +18,27 @@ const setup_billing = () => {
|
||||
label: __("Billing Name"),
|
||||
fieldname: "billing_name",
|
||||
reqd: 1,
|
||||
default: address && address.billing_name,
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("Address Line 1"),
|
||||
fieldname: "address_line1",
|
||||
reqd: 1,
|
||||
default: address && address.address_line1,
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("Address Line 2"),
|
||||
fieldname: "address_line2",
|
||||
default: address && address.address_line2,
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("City/Town"),
|
||||
fieldname: "city",
|
||||
reqd: 1,
|
||||
default: address && address.city,
|
||||
},
|
||||
{
|
||||
fieldtype: "Column Break",
|
||||
@@ -43,6 +47,7 @@ const setup_billing = () => {
|
||||
fieldtype: "Data",
|
||||
label: __("State/Province"),
|
||||
fieldname: "state",
|
||||
default: address && address.state,
|
||||
},
|
||||
{
|
||||
fieldtype: "Link",
|
||||
@@ -51,18 +56,24 @@ const setup_billing = () => {
|
||||
options: "Country",
|
||||
reqd: 1,
|
||||
only_select: 1,
|
||||
default: address && address.country,
|
||||
change: () => {
|
||||
change_currency();
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("Postal Code"),
|
||||
fieldname: "pincode",
|
||||
reqd: 1,
|
||||
default: address && address.pincode,
|
||||
},
|
||||
{
|
||||
fieldtype: "Data",
|
||||
label: __("Phone Number"),
|
||||
fieldname: "phone",
|
||||
reqd: 1,
|
||||
default: address && address.phone,
|
||||
},
|
||||
{
|
||||
fieldtype: "Section Break",
|
||||
@@ -143,3 +154,33 @@ const handle_success = (response, doctype, docname, address, order_id) => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const change_currency = () => {
|
||||
let country = this.billing.get_value("country");
|
||||
if (exception_country.includes(country)) {
|
||||
update_price(original_price_formatted);
|
||||
return;
|
||||
}
|
||||
frappe.call({
|
||||
method: "lms.lms.utils.change_currency",
|
||||
args: {
|
||||
country: country,
|
||||
amount: amount,
|
||||
currency: currency,
|
||||
},
|
||||
callback: (data) => {
|
||||
let current_price = $(".total-price").text();
|
||||
if (current_price != data.message) {
|
||||
update_price(data.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const update_price = (price) => {
|
||||
$(".total-price").text(price);
|
||||
frappe.show_alert({
|
||||
message: "Total Price has been updated.",
|
||||
indicator: "yellow",
|
||||
});
|
||||
};
|
||||
|
||||
@@ -14,10 +14,17 @@ def get_context(context):
|
||||
|
||||
validate_access(doctype, docname, module)
|
||||
get_billing_details(context)
|
||||
context.original_amount = context.amount
|
||||
context.original_currency = context.currency
|
||||
context.exception_country = frappe.get_all(
|
||||
"Payment Country", filters={"parent": "LMS Settings"}, pluck="country"
|
||||
)
|
||||
|
||||
context.amount, context.currency = check_multicurrency(
|
||||
context.amount, context.currency
|
||||
)
|
||||
|
||||
context.address = get_address()
|
||||
if context.currency == "INR":
|
||||
context.amount, context.gst_applied = apply_gst(context.amount, None)
|
||||
|
||||
@@ -75,3 +82,35 @@ def get_billing_details(context):
|
||||
context.title = details.title
|
||||
context.amount = details.amount
|
||||
context.currency = details.currency
|
||||
|
||||
|
||||
def get_address():
|
||||
address = frappe.get_all(
|
||||
"Address",
|
||||
{"email_id": frappe.session.user},
|
||||
[
|
||||
"address_title as billing_name",
|
||||
"address_line1",
|
||||
"address_line2",
|
||||
"city",
|
||||
"state",
|
||||
"country",
|
||||
"pincode",
|
||||
"phone",
|
||||
],
|
||||
order_by="creation desc",
|
||||
limit=1,
|
||||
)
|
||||
|
||||
if not len(address):
|
||||
return None
|
||||
else:
|
||||
address = address[0]
|
||||
|
||||
if not address.address_line2:
|
||||
address.address_line2 = ""
|
||||
|
||||
if not address.state:
|
||||
address.state = ""
|
||||
|
||||
return address
|
||||
|
||||
Reference in New Issue
Block a user