Fixes related to schools fees

This commit is contained in:
Nabin Hait 2017-09-19 17:22:30 +05:30
parent 0664d6ed8b
commit 6960a76adc
6 changed files with 96 additions and 85 deletions

View File

@ -62,10 +62,8 @@ frappe.ui.form.on('Fee Schedule', {
if (frm.doc.fee_creation_status=="In Process") {
frm.dashboard.add_progress("Fee Creation Status", "0");
}
if (!frm.doc.__islocal && !frm.doc.fee_creation_status || frm.doc.fee_creation_status == "Failed") {
if (frm.doc.docstatus==1 && !frm.doc.fee_creation_status || frm.doc.fee_creation_status == "Failed") {
frm.add_custom_button(__('Create Fees'), function() {
frm.doc.fee_creation_status = "In Process";
frm.save();
frappe.call({
method: "create_fees",
doc: frm.doc,
@ -75,9 +73,6 @@ frappe.ui.form.on('Fee Schedule', {
});
}, "fa fa-play", "btn-success");
}
if (frm.doc.fee_creation_status==="Successful") {
frm.set_read_only();
}
},
fee_structure: function(frm) {
@ -104,6 +99,8 @@ frappe.ui.form.on("Fee Schedule Student Group", {
method: "erpnext.schools.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) {

View File

@ -1,7 +1,7 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_import": 1,
"allow_rename": 0,
"autoname": "naming_series:",
"beta": 1,
@ -151,7 +151,7 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Send Email",
"label": "Send Payment Request Email",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -1025,11 +1025,11 @@
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-09-12 02:03:37.062064",
"modified": "2017-09-19 16:24:17.266071",
"modified_by": "Administrator",
"module": "Schools",
"name": "Fee Schedule",
@ -1037,23 +1037,23 @@
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"amend": 1,
"apply_user_permissions": 0,
"cancel": 0,
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
"export": 0,
"export": 1,
"if_owner": 0,
"import": 0,
"import": 1,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 0,
"report": 1,
"role": "Academics User",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"submit": 1,
"write": 1
}
],

View File

@ -3,7 +3,7 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
import frappe, erpnext
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
from frappe.utils import money_in_words
@ -17,13 +17,19 @@ class FeeSchedule(Document):
self.set_onload('dashboard_info', info)
def get_dashboard_info(self):
total_unpaid = frappe.db.sql("""select sum(outstanding_amount) from tabFees
where fee_schedule=%s""", (self.name))
total_unpaid_amount = flt(total_unpaid[0][0]) if total_unpaid else 0
info = {}
info["total_paid"] = self.grand_total - total_unpaid_amount
info["total_unpaid"] = total_unpaid_amount
info["currency"] = frappe.defaults.get_defaults().currency
info = {
"total_paid": 0,
"total_unpaid": 0,
"currency": erpnext.get_company_currency(self.company)
}
fees_amount = frappe.db.sql("""select sum(grand_total), sum(outstanding_amount) from tabFees
where fee_schedule=%s and docstatus=1""", (self.name))
if fees_amount:
info["total_paid"] = flt(fees_amount[0][0]) - flt(fees_amount[0][1])
info["total_unpaid"] = flt(fees_amount[0][1])
return info
def validate(self):
@ -33,16 +39,18 @@ class FeeSchedule(Document):
no_of_students = 0
for d in self.student_groups:
# if not d.total_students:
d.total_students = get_total_students(d.student_group, self.student_category)
d.total_students = get_total_students(d.student_group, self.academic_year,
self.academic_term, self.student_category)
no_of_students += cint(d.total_students)
self.grand_total = no_of_students*self.total_amount
self.grand_total_in_words = money_in_words(self.grand_total)
def create_fees(self):
if self.fee_creation_status == "In Process":
frappe.publish_realtime("fee_schedule_progress", {"progress": "0", "reload": 1}, user=frappe.session.user)
enqueue(generate_fee, queue='default', timeout=6000, event='generate_fee',
fee_schedule=self.name)
self.db_set("fee_creation_status", "In Process")
frappe.publish_realtime("fee_schedule_progress",
{"progress": "0", "reload": 1}, user=frappe.session.user)
enqueue(generate_fee, queue='default', timeout=6000, event='generate_fee',
fee_schedule=self.name)
def generate_fee(fee_schedule):
doc = frappe.get_doc("Fee Schedule", fee_schedule)
@ -87,7 +95,8 @@ def generate_fee(fee_schedule):
frappe.db.set_value("Fee Schedule", fee_schedule, "fee_creation_status", "Successful")
frappe.db.set_value("Fee Schedule", fee_schedule, "error_log", None)
frappe.publish_realtime("fee_schedule_progress", {"progress": "100", "reload": 1}, user=frappe.session.user)
frappe.publish_realtime("fee_schedule_progress",
{"progress": "100", "reload": 1}, user=frappe.session.user)
@frappe.whitelist()
@ -99,17 +108,21 @@ def get_fee_structure(source_name,target_doc=None):
return fee_request
@frappe.whitelist()
def get_total_students(student_group, student_category=None):
def get_total_students(student_group, academic_year, academic_term=None, student_category=None):
conditions = ""
if student_category:
conditions = " and s.student_category='{}'".format(frappe.db.escape(student_category))
conditions = " and pe.student_category='{}'".format(frappe.db.escape(student_category))
if academic_term:
conditions = " and pe.academic_term='{}'".format(frappe.db.escape(academic_term))
return frappe.db.sql("""
select count(s.name)
from `tabStudent` s, `tabStudent Group Student` sgs
select count(pe.name)
from `tabStudent Group Student` sgs, `tabProgram Enrollment` pe
where
s.name = sgs.student
pe.student = sgs.student
and pe.academic_year = %s
and sgs.parent = %s
and sgs.active = 1
{conditions}
""".format(conditions=conditions), student_group)[0][0]
""".format(conditions=conditions), (academic_year, student_group))[0][0]

View File

@ -4,8 +4,6 @@
frappe.ui.form.on("Fees", {
setup: function(frm) {
frm.add_fetch("student", "title", "student_name");
frm.add_fetch("student", "student_email_id", "student_email");
frm.add_fetch("fee_structure", "receivable_account", "receivable_account");
frm.add_fetch("fee_structure", "income_account", "income_account");
frm.add_fetch("fee_structure", "cost_center", "cost_center");

View File

@ -93,6 +93,7 @@
"label": "Student Name",
"length": 0,
"no_copy": 0,
"options": "student.student_name",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -136,37 +137,6 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "",
"fieldname": "send_payment_request",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Send Payment Request",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -198,6 +168,37 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "",
"fieldname": "send_payment_request",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Send Payment Request",
"length": 0,
"no_copy": 1,
"permlevel": 0,
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -505,13 +506,14 @@
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fieldname": "student_email",
"fieldtype": "Data",
"hidden": 1,
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
@ -526,7 +528,7 @@
"precision": "",
"print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 1,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
@ -1274,7 +1276,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2017-09-11 16:04:35.725204",
"modified": "2017-09-19 16:45:14.313744",
"modified_by": "Administrator",
"module": "Schools",
"name": "Fees",

View File

@ -4,14 +4,13 @@
from __future__ import unicode_literals
from frappe.model.document import Document
import frappe
import frappe, erpnext
from frappe import _
from frappe.utils import money_in_words
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from frappe.utils.csvutils import getlink
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.accounts.general_ledger import delete_gl_entries
from erpnext.schools.api import get_student_guardians
class Fees(AccountsController):
@ -32,10 +31,11 @@ class Fees(AccountsController):
if not self.company:
self.company = frappe.defaults.get_defaults().company
if not self.currency:
self.currency = frappe.defaults.get_defaults().currency
self.currency = erpnext.get_company_currency(self.company)
if not (self.receivable_account and self.income_account and self.cost_center):
accounts_details = frappe.get_all("Company", fields=["default_receivable_account",
"default_income_account", "cost_center"], filters={"name": self.company})[0]
accounts_details = frappe.get_all("Company",
fields=["default_receivable_account", "default_income_account", "cost_center"],
filters={"name": self.company})[0]
if not self.receivable_account:
self.receivable_account = accounts_details.default_receivable_account
if not self.income_account:
@ -46,13 +46,14 @@ class Fees(AccountsController):
self.student_email = self.get_student_emails()
def get_student_emails(self):
guardians = get_student_guardians(self.student)
email_list = []
for guardian in guardians:
email = frappe.db.get_value("Guardian", guardian.guardian, "email_address")
if email:
email_list.append(email)
return ", ".join(email_list)
student_emails = frappe.db.sql_list("""
select g.email_address
from `tabGuardian` g, `tabStudent Guardian` sg
where g.name = sg.guardian and sg.parent = %s and sg.parenttype = 'Student'
""", self.student)
student_emails.append(frappe.db.get_value("Student", self.student, "student_email_id"))
return ", ".join(list(set(student_emails)))
def calculate_total(self):