Override core functions of frappe and not doctypes using Monkey Patch

Currently there is no way to override standard methods of DocType class.

 · 1 min read

Currently there is no way to override standard methods of DocType class.

There are a lot of discussions on this topic. And the suggested solution is this one:

https://discuss.erpnext.com/t/how-to-override-method-in-frappe/28786/4

This overrides the method directly by setting the method on the class object. If this line is not called in a method, then the method will stay after the request is complete, so if there are other sites that don't have that app installed, they will be affected by the custom method behavior.

You can now override a standard DocType class via hooks.

test_app/hooks.py

override_doctype_class = {

'ToDo': 'test_app.overrides.CustomToDo'

}

test_app/overrides.py

import frappefrom frappe.desk.doctype.todo.todo import ToDoclass CustomToDo(ToDo):

def on_update(self):

 self.my_custom_code()

 super(ToDo, self).on_update()


def my_custom_code(self):

 pass

 Docs Link: https://github.com/frappe/frappe_docs/pull/45/files#diff-059ec755822aab5a151ab63bb8792c10R388

 Test

Book a free 30min tailored consultation

Free first 30min of enterprise consultation to manage your business better using digital processes.


Add a comment
Ctrl+Enter to add comment

W
Test 2 months ago

Who built this? why all strikethrough.

G
Gopi 1 year ago

in init.py override working well

F
Furqan Asghar 3 years ago

HI Apoorv,in

Why all text on this post is strikethrough?