How to override method in frappe?

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

:hammer: python console :hammer:

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:

17 Likes