How to assign a DocType's children(items) to another DocType?

Hello,

This function is called from a hook. It passes a doc of type “Fees”. It is supposed to extract some of the attributes in Fee and use it to create a new doc of type “Sales Invoice”.

I am stuck at assigning doc.components from “Fees” to items in the new “Sales Invoice”. Any pointers will be appreciated. pls note, doc.components has fields fees_category and amount that I want to copy to ‘description’ and ‘amount’ in “Sales Invoice → items” respectively.

def NewFeeInv2(doc, method):
    feeinv = frappe.get_doc({
                'doctype': "Sales Invoice",
                'naming_series': 'SINV-',
                'posting_date': doc.creation,
                'base_grand_total': float(doc.total_amount),
                
                "items":[{????????}]
})
#prepare items

items=[]
for d in doc.fees_child_table:
  items.append({
      "item_code": d.fee_companent,
       ....
   })

feeinv = frappe.get_doc({
       "doctype": "Sales Invoice",
       "items": items
     })

Thanks @saurabh6790, works like a charm :slight_smile: