Autonaming through custom app not workin

Hello,
I am trying to make autoname of Sales Invoice through my custom app. I have written following doc event in my custom app’s hooks.py
“Sales Invoice”: {
“before_insert”: “app_name.module_name.sales_invoice.si_autoname”,
“validate”: “app_name.module_name.sales_invoice.validate”,
},
and in my sales_invoice.py file which i have kept in my custom app is as below

from frappe.model.naming import make_autoname

def si_autoname(doc, method):
    if doc.custom_field:
        doc.name = make_autoname("SINV-" + doc.custom_field + '-.##')      
    else:
        doc.name = make_autoname("SINV"+ '-.##')
       

def validate(doc, method):
    frappe.msgprint("hi")

on saving new entry it gives following error:
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 52, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 254, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 188, in insert
self.set_new_name()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 334, in set_new_name
set_new_name(self)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py”, line 38, in set_new_name
doc.run_method(“autoname”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 889, in composer
hooks.append(frappe.get_attr(handler))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 887, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: ‘module’ object has no attribute ‘autoname’

somehow my validate event is working perfectly but autonaming is not. what could be reason behind it? Am I doing it correct ? please help if someone knows about this. :slight_smile:
Thanks in advance…

Maybe you hooked autoname before, but did not call bench --site sitename clear-cache

@rmehta Okay Thanks I will try that out.