Home Featured How To Override a Method in Frappe or ERPNext

How To Override a Method in Frappe or ERPNext

by karani

When you are customizing an ERPNext instance, or you are building your own custom application using the Frappe Framework, there are some things you will find already done. Most of the time, these do not necessarily satisfy all our requirements. We may need to do a few changes here and there to suit our specific case.

Best practices dictate that we are not supposed to touch code written by Frappe or ERPNext teams. This is for the simple reason that in case they have an update, you will not be able to update your system, as your customization will be lost.

If you need to alter methods written by these teams, you will need to override the method with your own custom method. This is done by introducing the override to the hooks file inside your custom application, and then pointing the hook to the place where the class containing your custom method is.

Custom Class Code

from erpnext.education.doctype.student.student import Student

class KARANIStudent(Student):
    def validate(self):
        print("\n\n\n Student Values are being validated! \n\n\n")

Hooks File Code
override_doctype_class = {
    "Student": "gch_custom.overrides.todo.KARANIStudent",

You may also like

Leave a Comment