Monkey Patch to add method in SalesInvoice

Monkey Patch to add method in SalesInvoice

Hello, I need to add a custom method in SalesInvoice DocType.
I’ve tried with no success to add a monkey patch in of my custom app as follow:
from erpnext.accounts.doctype.sales_invoice.sales_invoice import SalesInvoice

def my_method(self):
    return 'Foo'

SalesInvoice.my_method = my_method

Any ideas?

what you need exactly to do?

Due frappe.db.sql doesn’t work in custom print format I need to add custom methods to SalesInvoice so I can call it in print format.

Did you try some of the other solutions before trying a monkey patch? They may (or may not) work for your scenario.