Try ERPNext Buy Support Partners Foundation

How to apply patch to change core class behavior?

I’d like to add some new behavior to base class Document class save, update and delete method without touching core frappe code.
After getting some idea about monkey patching I’ve written a patch but it does not execute any more.

Here is my patch code:

from __future__ import unicode_literals
from frappe.model.document import Document
import frappe

def execute():
    Document.newSave = Document.save 
    
    def newSave(self, ignore_permissions=None):
        print "I am here, Hizbul Bahar"
    Document.save = newSave

Can you please suggest me a way so that I can achieve my expectation?

Did you manage?

you should write that in the init file of your custom app …
refer to this
https://github.com/ElasticRun/latte/blob/master/latte/init.py

this is the entry point for monkey patching

1 Like