[bug fix] Fixed bug in fee caclulation, renamed functions
This commit is contained in:
parent
8793b823af
commit
f02a0d4d24
@ -94,13 +94,13 @@ def get_fee_structure(program, academic_term=None):
|
||||
return fee_structure[0].name if fee_structure else None
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_fee_amount(fee_structure):
|
||||
"""Returns Fee Amount.
|
||||
def get_fee_components(fee_structure):
|
||||
"""Returns Fee Components.
|
||||
|
||||
:param fee_structure: Fee Structure.
|
||||
"""
|
||||
if fee_structure:
|
||||
fs = frappe.get_list("Fee Amount", fields=["fees_category", "amount"] , filters={"parent": fee_structure}, order_by= "idx")
|
||||
fs = frappe.get_list("Fee Component", fields=["fees_category", "amount"] , filters={"parent": fee_structure}, order_by= "idx")
|
||||
return fs
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -1,8 +1,8 @@
|
||||
frappe.ui.form.on("Fee Amount", {
|
||||
frappe.ui.form.on("Fee Component", {
|
||||
amount: function(frm) {
|
||||
total_amount = 0;
|
||||
for(var i=0;i<frm.doc.amount.length;i++) {
|
||||
total_amount += frm.doc.amount[i].amount;
|
||||
for(var i=0;i<frm.doc.components.length;i++) {
|
||||
total_amount += frm.doc.components[i].amount;
|
||||
}
|
||||
frm.set_value("total_amount", total_amount);
|
||||
}
|
||||
|
@ -46,34 +46,39 @@ frappe.ui.form.on("Fees", {
|
||||
},
|
||||
|
||||
fee_structure: function(frm) {
|
||||
frm.set_value("amount" ,"");
|
||||
frm.set_value("components" ,"");
|
||||
if (frm.doc.fee_structure) {
|
||||
frappe.call({
|
||||
method: "erpnext.schools.api.get_fee_amount",
|
||||
method: "erpnext.schools.api.get_fee_components",
|
||||
args: {
|
||||
"fee_structure": frm.doc.fee_structure
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
$.each(r.message, function(i, d) {
|
||||
var row = frappe.model.add_child(frm.doc, "Fee Amount", "amount");
|
||||
var row = frappe.model.add_child(frm.doc, "Fee Component", "components");
|
||||
row.fees_category = d.fees_category;
|
||||
row.amount = d.amount;
|
||||
});
|
||||
}
|
||||
refresh_field("amount");
|
||||
refresh_field("components");
|
||||
frm.trigger("calculate_total_amount");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
frappe.ui.form.on("Fee Amount", {
|
||||
amount: function(frm) {
|
||||
calculate_total_amount: function(frm) {
|
||||
total_amount = 0;
|
||||
for(var i=0;i<frm.doc.amount.length;i++) {
|
||||
total_amount += frm.doc.amount[i].amount;
|
||||
for(var i=0;i<frm.doc.components.length;i++) {
|
||||
total_amount += frm.doc.components[i].amount;
|
||||
}
|
||||
frm.set_value("total_amount", total_amount);
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Fee Component", {
|
||||
amount: function(frm) {
|
||||
frm.trigger("calculate_total_amount");
|
||||
}
|
||||
});
|
||||
|
@ -27,11 +27,11 @@ class ProgramEnrollment(Document):
|
||||
frappe.db.set_value("Student", self.student, "joining_date", date)
|
||||
|
||||
def make_fee_records(self):
|
||||
from erpnext.schools.api import get_fee_amount
|
||||
from erpnext.schools.api import get_fee_components
|
||||
fee_list = []
|
||||
for d in self.fees:
|
||||
fee_amount = get_fee_amount(d.fee_structure)
|
||||
if fee_amount:
|
||||
fee_components = get_fee_components(d.fee_structure)
|
||||
if fee_components:
|
||||
fees = frappe.new_doc("Fees")
|
||||
fees.update({
|
||||
"student": self.student,
|
||||
@ -42,7 +42,7 @@ class ProgramEnrollment(Document):
|
||||
"due_date": d.due_date,
|
||||
"student_name": self.student_name,
|
||||
"program_enrollment": self.name,
|
||||
"amount": fee_amount
|
||||
"components": fee_components
|
||||
})
|
||||
|
||||
fees.save()
|
||||
|
Loading…
Reference in New Issue
Block a user