pythonerpnextfrappe

How can we add child table dynamically in frappe (ERPNEXT)


I want to add child tables dynamically depending on records in another doctype.


Solution

  • There are several method to add child in parent doc:

    Method 1:

    `

    import frappe
    parent = frappe.get_doc('Sales Order', 'SO-00002')
    child = frappe.new_doc("Sales Order Item")
    child.update({
        'company': 'company_name',
        'item_code': 'item_code',
        'item_name': 'item_name',
        'field': 'field_value'
        'parent': parent.name,
        'parenttype': 'Sales Order',
        'parentfield': 'items'
    })
    parent.items.append(child)
    

    Method 2:

    import frappe
    
    parent = frappe.get_doc('Sales Order', 'SO-00002')
    child = frappe._dict({
         'company': 'company_name',
        'item_code': 'item_code',
        'item_name': 'item_name',
        'field': 'field_value'
    })
    parent.items.append(child)
    

    `