Create Delivery Note from Sales Order (maped document)

Hi all,

I create a custom button to create a Delivery Note (automatically) from Sales Order and submit it (while creating)


Problem

while creating a Delivery Note the Sales Order status is not changed

  • from (To Deliver To Bill) to (To Bill)

My Code

frappe.db.insert({
			'doctype': 'Delivery Note',
			'customer': frm.doc.customer,
			'set_warehouse': frm.doc.set_warehouse,
			'selling_price_list': 'Standard Selling',
			'docstatus':1,
			'items': frm.doc.items.map((item) => {
				return {
					'item_code' : item.item_code,
					'item_name' : item.item_name,
					'rate' : item.rate,
					'qty':item.qty,
					'against_sales_order': frm.doc.name
				};
			})
		}).then(doc => {
			console.log(doc.name)
			frappe.show_alert("Delivery Note is created successfully")
		});

Expected Result

Screenshot from 2022-12-15 13-30-29
Screenshot from 2022-12-15 13-26-41


My Code Result

Screenshot from 2022-12-15 13-21-14

What is missing in my Code ?

Hi @Omar_Mohammed,

Please apply it.

frappe.db.insert({
    'doctype': 'Delivery Note',
	'customer': frm.doc.customer,
	'set_warehouse': frm.doc.set_warehouse,
	'selling_price_list': 'Standard Selling',
	'docstatus':1,
	'items': frm.doc.items.map((item) => {
	    return {
			'item_code' : item.item_code,
			'item_name' : item.item_name,
			'rate' : item.rate,
			'qty':item.qty,
			'against_sales_order': frm.doc.name,
			'so_detail': item.name
		};
	})
}).then(doc => {
	console.log(doc.name);
	frappe.show_alert("Delivery Note is created successfully");
});

The problem is that you have not added a so_detail.
I have tested it on my side so it’s worked perfectly.

Then reload and check it.

Thank You!

2 Likes

Thank you so much, for your solution :clap: