How to Use Monkey Patching in ERPNext?

Monkey patching is a technique in computer programming where existing code is modified dynamically at runtime. In ERPNext, monkey patching can be used to extend or modify the behaviour of software without changing the core code.

One common use case for monkey patching in ERPNext is to customize existing functionality or add new functionality to the system. For example, if a user wants to add a custom validation rule to a specific field in a form, they can write a monkey patch that modifies the validation function for that field.

A Stepwise Procedure to Use Monkey Patching in ERPNext

Let's understand this with an example where we have to override Frappe signup function and change already registered button to already sign up button shown below screenshot.

centered image


Step 1

Firstly you have to check function path in network which you want to override and click on post API URL (Highlighted in screenshot) and then go in request.



Step 2

Go to Frappe files, find the file and function which are mentioned in request (Sign up function). Here, we can also change already registered to already sign up in line no. 836.



Step 3

Create a python file in your custom app, create function and then update the already registered to already sign up.



Step 4

Go to init.py file and import default function, custom function and override it.



Step 5

Finally, the default Frappe function with monkey patching is updated.





Conclusion

Overall, monkey patching can be a powerful tool for ERPNext developers and users who want to customize the software to meet their specific needs or address issues in a timely manner.

Written by:

Pardeep Singh
ERPNext Developer

    last updated 11 months ago