diff --git a/education/education/doctype/fee_schedule/fee_schedule.js b/education/education/doctype/fee_schedule/fee_schedule.js index d74af0ce..bac4a280 100644 --- a/education/education/doctype/fee_schedule/fee_schedule.js +++ b/education/education/doctype/fee_schedule/fee_schedule.js @@ -3,162 +3,178 @@ frappe.provide("erpnext.accounts.dimensions"); frappe.ui.form.on("Fee Schedule", { - company: function (frm) { - erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); - }, + company: function (frm) { + erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); + }, - onload: function (frm) { - frm.set_query("receivable_account", function (doc) { - return { - filters: { - account_type: "Receivable", - is_group: 0, - company: doc.company, - }, - }; - }); + onload: function (frm) { + frm.set_query("receivable_account", function (doc) { + return { + filters: { + account_type: "Receivable", + is_group: 0, + company: doc.company, + }, + }; + }); - frm.set_query("income_account", function (doc) { - return { - filters: { - account_type: "Income Account", - is_group: 0, - company: doc.company, - }, - }; - }); + frm.set_query("income_account", function (doc) { + return { + filters: { + account_type: "Income Account", + is_group: 0, + company: doc.company, + }, + }; + }); - frm.set_query("academic_term", function (doc) { - return { - filters: { - academic_year: doc.academic_year, - }, - }; - }); + frm.set_query("academic_term", function (doc) { + return { + filters: { + academic_year: doc.academic_year, + }, + }; + }); - frm.set_query("student_group", "student_groups", function () { - return { - filters: { - program: frm.doc.program, - academic_term: frm.doc.academic_term, - academic_year: frm.doc.academic_year, - disabled: 0, - }, - }; - }); + frm.set_query("student_group", "student_groups", function () { + return { + filters: { + program: frm.doc.program, + academic_term: frm.doc.academic_term, + academic_year: frm.doc.academic_year, + disabled: 0, + }, + }; + }); - frappe.realtime.on("fee_schedule_progress", function (data) { - if (data.reload && data.reload === 1) { - frm.reload_doc(); - } - if (data.progress) { - let progress_bar = $(cur_frm.dashboard.progress_area.body).find( - ".progress-bar" - ); - if (progress_bar) { - $(progress_bar) - .removeClass("progress-bar-danger") - .addClass("progress-bar-success progress-bar-striped"); - $(progress_bar).css("width", data.progress + "%"); - } - } - }); + frappe.realtime.on("fee_schedule_progress", function (data) { + if (data.reload && data.reload === 1) { + frm.reload_doc(); + } + if (data.progress) { + let progress_bar = $(cur_frm.dashboard.progress_area.body).find( + ".progress-bar" + ); + if (progress_bar) { + $(progress_bar) + .removeClass("progress-bar-danger") + .addClass("progress-bar-success progress-bar-striped"); + $(progress_bar).css("width", data.progress + "%"); + } + } + }); - erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); - }, + erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype); + }, - refresh: function (frm) { - if ( - !frm.doc.__islocal && - frm.doc.__onload && - frm.doc.__onload.dashboard_info && - frm.doc.fee_creation_status === "Successful" - ) { - var info = frm.doc.__onload.dashboard_info; - frm.dashboard.add_indicator( - __("Total Collected: {0}", [ - format_currency(info.total_paid, info.currency), - ]), - "blue" - ); - frm.dashboard.add_indicator( - __("Total Outstanding: {0}", [ - format_currency(info.total_unpaid, info.currency), - ]), - info.total_unpaid ? "orange" : "green" - ); - } - if (frm.doc.fee_creation_status === "In Process") { - frm.dashboard.add_progress("Fee Creation Status", "0"); - } - if ( - (frm.doc.docstatus === 1 && !frm.doc.fee_creation_status) || - frm.doc.fee_creation_status === "Failed" - ) { - let button_label = "Create Sales Invoice"; - // frappe.db.get_value get only create_so field from Education Settings - frappe.db.get_value("Education Settings", {}, "create_so", (r) => { - if (+r.create_so) { - button_label = "Create Sales Order"; - } - frm.add_custom_button(__(button_label), function () { - frappe.call({ - method: "create_fees", - doc: frm.doc, - callback: function () { - frm.refresh(); - }, - }); - }); - }); - } - if (frm.doc.fee_creation_status === "Successful") { - frm.add_custom_button(__("View Sales Invoice Records"), function () { - frappe.route_options = { - fee_schedule: frm.doc.name, - }; - frappe.set_route("List", "Sales Invoice"); - }); - } - }, + refresh: function (frm) { + if ( + !frm.doc.__islocal && + frm.doc.__onload && + frm.doc.__onload.dashboard_info && + frm.doc.fee_creation_status === "Successful" + ) { + var info = frm.doc.__onload.dashboard_info; + frm.dashboard.add_indicator( + __("Total Collected: {0}", [ + format_currency(info.total_paid, info.currency), + ]), + "blue" + ); + frm.dashboard.add_indicator( + __("Total Outstanding: {0}", [ + format_currency(info.total_unpaid, info.currency), + ]), + info.total_unpaid ? "orange" : "green" + ); + } + if (frm.doc.fee_creation_status === "In Process") { + frm.dashboard.add_progress("Fee Creation Status", "0"); + } + if ( + (frm.doc.docstatus === 1 && !frm.doc.fee_creation_status) || + frm.doc.fee_creation_status === "Failed" + ) { + let button_label = "Create Sales Invoice"; - fee_structure: function (frm) { - if (frm.doc.fee_structure) { - frappe.call({ - method: - "education.education.doctype.fee_schedule.fee_schedule.get_fee_structure", - args: { - target_doc: frm.doc.name, - source_name: frm.doc.fee_structure, - }, - callback: function (r) { - var doc = frappe.model.sync(r.message); - frappe.set_route("Form", doc[0].doctype, doc[0].name); - }, - }); - } - }, + frappe.db.get_value("Education Settings", {}, "create_so", (r) => { + // convert r.create_so to number + if (+r.create_so) { + button_label = "Create Sales Order"; + // set indicator in the frm + } + frm.add_custom_button(__(button_label), function () { + frappe.call({ + method: "create_fees", + doc: frm.doc, + callback: function () { + frm.refresh(); + }, + }); + }); + }); + } + if (frm.doc.fee_creation_status === "Successful") { + frm.add_custom_button( + __("View Sales Order"), + function () { + frappe.route_options = { + fee_schedule: frm.doc.name, + }; + frappe.set_route("List", "Sales Order"); + }, + __("View Records") + ); + frm.add_custom_button( + __("View Sales Invoice"), + function () { + frappe.route_options = { + fee_schedule: frm.doc.name, + }; + frappe.set_route("List", "Sales Invoice"); + }, + __("View Records") + ); + } + }, + + fee_structure: function (frm) { + if (frm.doc.fee_structure) { + frappe.call({ + method: + "education.education.doctype.fee_schedule.fee_schedule.get_fee_structure", + args: { + target_doc: frm.doc.name, + source_name: frm.doc.fee_structure, + }, + callback: function (r) { + var doc = frappe.model.sync(r.message); + frappe.set_route("Form", doc[0].doctype, doc[0].name); + }, + }); + } + }, }); frappe.ui.form.on("Fee Schedule Student Group", { - student_group: function (frm, cdt, cdn) { - var row = locals[cdt][cdn]; - if (row.student_group && frm.doc.academic_year) { - frappe.call({ - method: - "education.education.doctype.fee_schedule.fee_schedule.get_total_students", - args: { - student_group: row.student_group, - academic_year: frm.doc.academic_year, - academic_term: frm.doc.academic_term, - student_category: frm.doc.student_category, - }, - callback: function (r) { - if (r.message) { - frappe.model.set_value(cdt, cdn, "total_students", r.message); - } - }, - }); - } - }, + student_group: function (frm, cdt, cdn) { + var row = locals[cdt][cdn]; + if (row.student_group && frm.doc.academic_year) { + frappe.call({ + method: + "education.education.doctype.fee_schedule.fee_schedule.get_total_students", + args: { + student_group: row.student_group, + academic_year: frm.doc.academic_year, + academic_term: frm.doc.academic_term, + student_category: frm.doc.student_category, + }, + callback: function (r) { + if (r.message) { + frappe.model.set_value(cdt, cdn, "total_students", r.message); + } + }, + }); + } + }, }); diff --git a/education/education/doctype/fee_schedule/fee_schedule.json b/education/education/doctype/fee_schedule/fee_schedule.json index b8cc6d16..19b5cb39 100644 --- a/education/education/doctype/fee_schedule/fee_schedule.json +++ b/education/education/doctype/fee_schedule/fee_schedule.json @@ -280,9 +280,13 @@ { "link_doctype": "Sales Invoice", "link_fieldname": "fee_schedule" + }, + { + "link_doctype": "Sales Order", + "link_fieldname": "fee_schedule" } ], - "modified": "2024-01-23 12:18:14.075608", + "modified": "2024-03-26 14:37:05.652436", "modified_by": "Administrator", "module": "Education", "name": "Fee Schedule", diff --git a/education/education/doctype/fee_schedule/fee_schedule.py b/education/education/doctype/fee_schedule/fee_schedule.py index 6cd0a0ff..724a8924 100644 --- a/education/education/doctype/fee_schedule/fee_schedule.py +++ b/education/education/doctype/fee_schedule/fee_schedule.py @@ -31,7 +31,7 @@ def get_dashboard_info(self): fees_amount = frappe.db.sql( """select sum(grand_total), sum(outstanding_amount) from `tabSales Invoice` - where fee_schedule=%s and docstatus=1 and student is not null""", + where fee_schedule=%s and docstatus=1 and student is not null""", (self.name), ) @@ -78,21 +78,21 @@ def create_fees(self): frappe.msgprint( _( """Fee records will be created in the background. - In case of any error the error message will be updated in the Schedule.""" + In case of any error the error message will be updated in the Schedule.""" ) ) enqueue( - generate_sales_invoice, + generate_fees, queue="default", timeout=6000, - event="generate_sales_invoice", + event="generate_fees", fee_schedule=self.name, ) else: - generate_sales_invoice(self.name) + generate_fees(self.name) -def generate_sales_invoice(fee_schedule): +def generate_fees(fee_schedule): doc = frappe.get_doc("Fee Schedule", fee_schedule) error = False total_records = sum([int(d.total_students) for d in doc.student_groups]) @@ -108,7 +108,10 @@ def generate_sales_invoice(fee_schedule): for student in students: try: student_id = student.student - create_sales_invoice(fee_schedule, student_id) + if frappe.db.get_single_value("Education Settings", "create_so"): + create_sales_order(fee_schedule, student_id) + else: + create_sales_invoice(fee_schedule, student_id) created_records += 1 frappe.publish_realtime( "fee_schedule_progress", @@ -246,13 +249,13 @@ def get_students( conditions += " and pe.academic_term={}".format(frappe.db.escape(academic_term)) students = frappe.db.sql( """ - select pe.student, pe.student_name, pe.program, pe.student_batch_name, pe.name as enrollment - from `tabStudent Group Student` sgs, `tabProgram Enrollment` pe - where - pe.docstatus = 1 and pe.student = sgs.student and pe.academic_year = %s - and sgs.parent = %s and sgs.active = 1 - {conditions} - """.format( + select pe.student, pe.student_name, pe.program, pe.student_batch_name, pe.name as enrollment + from `tabStudent Group Student` sgs, `tabProgram Enrollment` pe + where + pe.docstatus = 1 and pe.student = sgs.student and pe.academic_year = %s + and sgs.parent = %s and sgs.active = 1 + {conditions} + """.format( conditions=conditions ), (academic_year, student_group), diff --git a/education/education/doctype/fee_schedule/fee_schedule_list.js b/education/education/doctype/fee_schedule/fee_schedule_list.js index e70f0f7f..9453c28d 100644 --- a/education/education/doctype/fee_schedule/fee_schedule_list.js +++ b/education/education/doctype/fee_schedule/fee_schedule_list.js @@ -1,13 +1,15 @@ frappe.listview_settings['Fee Schedule'] = { add_fields: ["fee_creation_status", "due_date", "grand_total"], - get_indicator: function(doc) { - if (doc.fee_creation_status=="Successful") { + get_indicator: function (doc) { + // + if (doc.fee_creation_status == "Successful") { return [__("Fee Created"), "green", "fee_creation_status,=,Successful"]; - } else if(doc.fee_creation_status == "In Process") { + } else if (doc.fee_creation_status == "In Process") { return [__("Creating Fees"), "orange", "fee_creation_status,=,In Process"]; - } else if(doc.fee_creation_status == "Failed") { + } else if (doc.fee_creation_status == "Failed") { return [__("Fee Creation Failed"), "red", "fee_creation_status,=,Failed"]; } else { + let label = "Fee Creation Pending" return [__("Fee Creation Pending"), "orange", "fee_creation_status,=,"]; } }