Autonaming through custom app not workin

I am trying to make autoname of Sales Invoice through my custom app. I have written following doc event in my custom app’s
“Sales Invoice”: {
“before_insert”: “app_name.module_name.sales_invoice.si_autoname”,
“validate”: “app_name.module_name.sales_invoice.validate”,
and in my 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: = make_autoname("SINV-" + doc.custom_field + '-.##')      
    else: = make_autoname("SINV"+ '-.##')

def validate(doc, method):

on saving new entry it gives following error:
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 55, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 52, in execute_cmd
return, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/”, line 22, in savedocs
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 254, in _save
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 188, in insert
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 334, in set_new_name
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 38, in set_new_name
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 889, in composer
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, 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.