Outstanding Balance and Overdue Balance for Student

The customer dashboard has displays account balance as on below screenshot. I would like to do the same for Student doctype (Outstanding Balance and Overdue Balance). I could not find any code in customer_dashboard.py
Any hint where I can find the codes?

customer

2 Likes

Thanks for the suggestion.

We will make this a feature in the core.

1 Like

Thank you. When can we see something to work with while more production is going on?

This is what I am using:
Add 2 custom fields: outstanding_amount and overdue_amount
In hooks.py

"Payment Entry": {
               "on_submit": "university.api.update_student_balance",
               "on_cancel": "university.api.update_student_balance"
},

In api.py

@frappe.whitelist()
def update_student_balance(doc, method):
    student_name = doc.party if doc.doctype == "Payment Entry" else doc.student
    student = frappe.get_doc("Student", student_name)
    sql_query = """SELECT sum(outstanding_amount)
                    FROM `tabFees` WHERE student='%s'
                    AND docstatus = 1
                    GROUP BY student
                """ % (student.name)

    result = frappe.db.sql(sql_query)
    student.outstanding_amount = result[0][0] if result else 0
    sql_query = """SELECT sum(outstanding_amount)
                   FROM `tabFees` WHERE student='%s'
                   AND docstatus = 1
                   AND due_date < '%s'
                   GROUP BY student
                """ % (student.name, datetime.datetime.now())
    result2 = frappe.db.sql(sql_query)
    student.overdue_amount = result[0][0] if result2 else 0
    student.save()
    frappe.db.commit()

Dears

you can add below script on payment entry before validation event

total_allocated_amount = sum(pr.allocated_amount for pr in doc.references)
doc.paid_amount = total_allocated_amount

it will be resolved