Autoname hook on Sales Invoice not working

I tried to make custom autoname for sales invoice but ‘autoname’ hook not fired, I used ‘before_insert’ instead. it got fired but the name still use default naming_series

Whats wrong?

Can you share your code?

@saurabh6790

def si_before_insert(self, method):
	self.name = self.my_order_no

the problem is frappe has made autoname using default series before executing before_insert hook

But autoname hook is not working,it works for other doctypes…can you give a clue?

thanks

You can also use the autoname function in the sales_invoice.py file. This should do the trick.

def autoname(self):
	self.name = self.my_order_no

changing core file shall break future updates…i want to do it via custom app…do you know why autoname hook not fired?

sales_invoice.py doesn’t has autoname method, that’s why autoname hook not working

Custom App - hooks.py

doc_events = {
	"Sales Invoice": {
		"autoname": "custom_app.hooked_methods.set_si_autoname"
	}
}

Created a hooked_methods.py file inside the custom_app -

import frappe

@frappe.whitelist()
def set_si_autoname(doc, method):
	doc.name = doc.po_no # or in your case doc.my_order_no

Seems to be working just fine.

2 Likes