How to override core python class method in custom python file?

import frappe
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice

def shoutout(self):

def before_cancel(self):

def build_my_thing():
SalesInvoice.shoutout = shoutout
SalesInvoice.before_cancel = before_cancel

I have tested above code but its not working in my case. As I have to override method which is linked with several methods in same core python file.
Here is my code
def g_entry(self):
print(“HELLO”) #this for test
earnings = self.get_salary_component_total(component_type = “earnings”) or {}
deductions = self.get_salary_component_total(component_type = “deductions”) or {}
default_payroll_payable_account = self.get_default_payroll_payable_account()
jv_name = “”
precision = frappe.get_precision(“Journal Entry Account”, “debit_in_account_currency”)

		if earnings or deductions:
			journal_entry = frappe.new_doc('Journal Entry')
			journal_entry.voucher_type = 'Journal Entry'
			journal_entry.user_remark = _('Accrual Journal Entry for salaries from {0} to {1}')\
				.format(self.start_date, self.end_date) =
			journal_entry.posting_date = self.posting_date

# I want add below line in this code in custom python file:
journal_entry.naming_series = self.naming_series
I am new ERPNEXT. Please Help Me…

I have same kind of problem, but I have to apply some condition in custom py file and I want to override the core class method in my custom file

Any solution on Override method then please suggest

my working code in the custom app’s is like below

from erpnext.stock.doctype.item.item import Item

def cant_change(self):

Item.cant_change = cant_change

@szufisher, Thank you so much.