Not able to create a new document with Child Table from Server Script

with the following server script I was able to create Purchase Receipt Doctype with Child table.
Note the child table from one Purchase Receipt was copied to another new Purchase receipt

for d in doc.get('items'):
   if d.item_code:
       pr = frappe.get_doc({
        "doctype" : "Purchase Receipt",
        "supplier": doc.supplier, 
        "supplier_name": doc.supplier_name, 
        "posting_date": doc.posting_date, 
        "posting_time": doc.posting_time,
		"items": [
		    {
		    "item_code" : d.item_code,
	        "description" : d.description,
            "qty": d.qty,
            "uom": d.uom,
	        "stock_uom": d.stock_uom,
	        "conversion_factor": d.conversion_factor,
            "rate": d.rate,
            "amount": d.amount,
            "base_rate": d.base_rate,
	        "base_amount" : d.base_amount
	        }
	   ]
	   })
pr.insert()
pr.save()
1 Like