Temporary sales invoice number before submit

Coming back to this thread with an almost working solution.
What I did is create a custom app and add these hooks :

doc_events = {
	"Sales Invoice": {
		"autoname": "numi.sales_invoice.draft_autoname",
		"on_submit": "numi.sales_invoice.draft_on_submit"


import frappe
from frappe.model.naming import make_autoname
from frappe.model.rename_doc import rename_doc

def draft_autoname(doc, method):
    doc.name = make_autoname("hash", doc.doctype)

    def draft_on_submit(doc, method):
        new_name = make_autoname(doc.naming_series, doc.doctype)
        rename_doc(doc.doctype, doc.name, new_name, force = True, ignore_permissions = False, show_alert = False)

This creates an invoice with a hash (4d1c91c3b3) and when submitted it is renamed correctly to ACC-SINV-2022-00003 for example. The only problem is after clicking on submit the form tries to reload on the same name (4d1c91c3b3) and gives an error Sales Invoice 4d1c91c3b3 not found because obviously it was changed in the on_submit method to ACC-SINV-2022-00003.
How can we deal with this ? Is there anything we can add to reload the form with the new name.


I finally found how Dokos did this, it wasn’t at ERPNext level but in the Core of Frappe giving the possibility to check a checkbox at Doctype creation to attribute naming series only after submission. I think this should be included in Frappe as the main behavior.

This is the commit that changed it :


Thanks @Merabtene

Here I made a PR with the solution provided by Dokos



:+1: this really good news. Would love to see it in v14.