Transcription
Hello, Everyone! Today, we will learn about populating data from one doctype to another using frappe.new_doc.
If you haven't watched my previous video on fetching data from one doctype to another, please do check it out. I have noticed many users facing this issue on the Frappe Forum. So let's dive in and explore it together.
Let's go to the sales invoice; we have to populate sales invoice parents data and child data into the Invoice Data. Go to the Invoice Data, Invoice Data doctype that I already created; so we have to create a client script. So open the client script, set the name like sales invoice to invoice data. Enable the script.
Now we have to set the condition like: if submitted sales invoice then will appear the custom button. So doc.docstatus is equal to 1; frm.add_custom_button Invoice Data, make a group button "Create".
Now, we have to test the button, so add the frappe.msgprint "clicked". Go to the sales invoice and reload the page; click on the button, so the button works properly. The comment out the frappe.msgprint.
Now we have to add the frappe.new_doc like invoice data; copy the doctype name and pass the parameter like inv; then we have to copy the invoice field name. So copy the sales invoice ID is equal to frm.doc.name; save it. Reload the page and test it. Create the invoice data; so here you can see sales invoice ID coming properly.
Now we have to set another child field like customer and we inv.company; copy the field name in. company is equal to sales invoice is company field name.
Now we have to get the sales invoice posting date. So we have to check the date field in sales invoice. So it's a posting date; save it. Reload the page. Again check it. So here you can see sales invoice parents data is coming properly.
Now we have to set the child table data. So back to the script frm.doc; now we have to copy the sales invoice item table field name and set it in the "for Loop" for each invoice invoice_item; let inv_item. We have to set the frappe model.add_child because we have to set the sales invoice child table data into the sales invoice, sorry invoice data doctype. So copy the field name. inv_item. Let's copy the field name item_code. Also we have to set the sales invoice item code field name. Let's reload the page. Create the invoice data; so all item codes are coming in properly. So let's configure the other child table field and set it. So copy this line and paste it: item name, item name, qty. But we have to check the field name of quantity in the sales invoice table; so it's also qty, unit of measure UOM, rate, rate. Also we have to add one more eow for the amount, amount. Save it.
Below the page, let's check the final output; so sales invoice data is properly populating in the invoice data, all details coming in properly. Let's select another sales invoice for testing; so it's working properly; save the data.
Thanks for watching! If you enjoy the video, please like 👍, share 🔗, and subscribe 🔔. Don't forget to leave a comment 💬 below. Thank You 🙏