feat: apply_gst in batches

This commit is contained in:
Jannat Patel
2023-09-11 22:44:28 +05:30
parent 07276f5c17
commit 04501143ec
10 changed files with 175 additions and 35 deletions

View File

@@ -30,7 +30,7 @@
<div class="">
<div class="flex mb-2">
<div class="field-label">
{% set label = "Course Name" if module == "course" else "Batch Name" %}
{% set label = "Course" if module == "course" else "Batch" %}
{{ _(label) }} : {{ title }}
</div>
</div>
@@ -40,6 +40,11 @@
{{ _("Total Price: ") }} {{ frappe.utils.fmt_money(amount, 2, currency) }}
</div>
</div>
{% if gst_applied %}
<span class="small mt-2">
{{ _("18% GST included") }}
</span>
{% endif %}
</div>
</div>
{% endmacro %}

View File

@@ -104,6 +104,7 @@ const generate_payment_link = (e) => {
doctype: doctype,
docname: docname,
phone: address.phone,
country: address.country,
},
callback: (data) => {
data.message.handler = (response) => {

View File

@@ -1,23 +1,30 @@
import frappe
from frappe import _
from lms.lms.utils import check_multicurrency, apply_gst
def get_context(context):
module = frappe.form_dict.module
docname = frappe.form_dict.modulename
doctype = "LMS Course" if module == "course" else "LMS Batch"
context.module = module
context.docname = docname
context.doctype = doctype
validate_access(doctype, docname, module)
get_billing_details(context)
check_multicurrency(context)
apply_gst(context)
def validate_access(doctype, docname, module):
if frappe.session.user == "Guest":
raise frappe.PermissionError(_("You are not allowed to access this page."))
if module not in ["course", "batch"]:
raise ValueError(_("Module is incorrect."))
doctype = "LMS Course" if module == "course" else "LMS Batch"
context.module = module
context.docname = docname
context.doctype = doctype
context.apply_gst = frappe.db.get_single_value("LMS Settings", "apply_gst")
if not frappe.db.exists(doctype, docname):
raise ValueError(_("Module Name is incorrect or does not exist."))
@@ -35,37 +42,32 @@ def get_context(context):
if membership:
raise frappe.PermissionError(_("You are already enrolled for this batch."))
if doctype == "LMS Course":
course = frappe.db.get_value(
def get_billing_details(context):
if context.doctype == "LMS Course":
details = frappe.db.get_value(
"LMS Course",
docname,
["title", "name", "paid_course", "course_price", "currency"],
context.docname,
["title", "name", "paid_course", "course_price as amount", "currency"],
as_dict=True,
)
if not course.paid_course:
if not details.paid_course:
raise frappe.PermissionError(_("This course is free."))
context.title = course.title
context.amount = course.course_price
context.currency = course.currency
else:
batch = frappe.db.get_value(
details = frappe.db.get_value(
"LMS Batch",
docname,
context.docname,
["title", "name", "paid_batch", "amount", "currency"],
as_dict=True,
)
if not batch.paid_batch:
if not details.paid_batch:
raise frappe.PermissionError(
_("To join this batch, please contact the Administrator.")
)
context.title = batch.title
context.amount = batch.amount
context.currency = batch.currency
if context.apply_gst:
context.gst_amount = context.amount * 1.18
context.title = details.title
context.amount = details.amount
context.currency = details.currency