Server Script for Auto Invoice from Sales Delivery

I want to generate sales invoice automatically after the sales delivery validation. To achieve this I created the Server script as per attached screenshot. Server script is running without any errors but the sales Invoice is not getting generated.

Script Type : DocType Event
Reference Document Type: Delivery Note
DoctType Event: After Submit

Script:
frappe.call('erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice',source_name = doc.name)

I need your to achieve this.

Thanks in advance.

1 Like

Hi @mangroliya,

Please apply a custom/client script and check it.

frappe.ui.form.on('Delivery Note', {
	on_submit(frm) {
		cur_frm.cscript.make_sales_invoice();
	}
});

When you submit the Delivery Note and automatically will open the sales invoice on a current page and then please click to save.

Thank You!

The below code is working. This code is creating Invoice automatically from delivery and same time submitting also.

facture = frappe.call('erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice',source_name = doc.name)
facture.docstatus = 1
#frappe.msgprint(facture.docstatus)

facture_doc = frappe.get_doc(
    facture
)
facture_doc.insert()
doc.reload()
1 Like