In custom_app module_name.py
import frappe
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice
def shoutout(self):
print("Yay!")
def before_cancel(self):
self.shoutout()
self.update_time_sheet(None)
def build_my_thing():
SalesInvoice.shoutout = shoutout
SalesInvoice.before_cancel = before_cancel
python console
In [1]: from custom_app.module_name import build_my_thing
In [2]: build_my_thing()
In [3]: sales_invoice = frappe.get_doc("Sales Invoice", "SINV-00165")
In [4]: sales_invoice.shoutout()
Yay!
In [5]: sales_invoice.cancel()
Yay!
more: