ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Overwriting Student Attendance Tool

customization

#1

Hi all,

I am trying to add a field to the student attendance tool. We are planning to mark attendance in the canteen using it, therefore they need to see allergy information. I would like to do this in a way that does not break updates, so I would like to avoid modifying any files in the frappe and erpnext app folders if at all possible.

We have a custom field called “Allergies” in the student doctype, and I have copied the student_attendance_tool.js and student_attendance_tool.py files to our custom app (that we’ve used for a variety of other useful tools and integrations which are very specific to our use case). I have modified the copied files to implement the functionality we need. All that remains is to figure out how to tell frappe to use our copy of it instead of the version in “frappe-bench/apps/erpnext/erpnext/education/doctype/student_attendance_tool”. What exactly do I need to put in my custom app’s hooks.py and/or the python file itself to get it to work?

Thanks,
James


#2

To my knowledge, there is no way to override entire doctypes (though it would be a tremendous help if there were one).

In the meantime, what you can do is use fixtures to add your custom fields
(see: Schema modification export (custom fields))

and use hooks.py to override specific methods
(see How to override method in frappe?)


#3

Ok, if I can’t override the entire doctype, could I override just the javascript, and call my own whitelisted python function from it to grab the allergy details and slot it into place?


#4

Yes, and for that you don’t even need to create a new app. For purely client-side stuff, I believe that you can do everything you’re wanting to do with just the Custom Script doctype (under the Setup module).


#5

Add in hooks.py of your custom app (e.g. from hooks.py of erpnext)

doctype_js = {
	"Communication": "public/js/communication.js",
}

You can just write client script with your js code, and call py functions in your custom app within that.

To overwrite python functions


#6

#7

You need to add you custom script file path in your hooks, he didn’t add in hooks you are right, because there are some other ways you can also make this work.
Like create a file in custom script from your admin panel.
To make it from custom app, first create the file like Purchase Receipt.js and add the file path in hooks.py
rigpl write the code from admin panel, export the fixture, and the script will automatically added in bench migrate