Try ERPNext Buy Support Partners Foundation

Inserting to Child Table Error 'datetime.date' object is not subscriptable'

Hi! I am trying to insert new record to a custom childtable in a custom doctype but I am having some trouble on inserting and submitting the child table through python. I tried different approaches like (doc.save() approach), still having the same error. Below is the code I am working with and also the error as image. Would really love to hear your thoughts on this.

def insertChildWWRS(doctype, parent_wwrs, customer, delivery_note_item, delivery_note, driver, date, vehicle):


checkWWRS = frappe.db.exists({
        'doctype':'Warehouse Withdrawal and Return Slip',
        'wwrs_driver':driver,
        'wwrs_plate_number_placeh': vehicle,
        'wwrs_date': date
    })


for x in range(len(delivery_note_item)):
    doc = frappe.get_doc("Warehouse Withdrawal and Return Slip", checkWWRS[0][0])

    childDict = {
        "outbound_customer": customer,
        "outbound_item": delivery_note_item[x].item_name,
        "outbound_qty":delivery_note_item[x].qty,
        "outbound_delivery_note": delivery_note
    }

    doc.append("outbound_cylinders", childDict)
    doc.insert()
    doc.submit()

Error

I really did not understand what went wrong with the last one, but to share my work around:

updated the code with this one:

def insertChildWWRS(doctype, parent_wwrs, customer, delivery_note_item, delivery_note, driver, date, vehicle):
checkWWRS = frappe.db.exists({
        'doctype':'Warehouse Withdrawal and Return Slip',
        'wwrs_driver':driver,
        'wwrs_plate_number_placeh': vehicle,
        'wwrs_date': date
    })


for x in range(len(delivery_note_item)):
    doc = frappe.get_doc("Warehouse Withdrawal and Return Slip", checkWWRS[0][0])

    test_dict = {
        "doctype": "WWRS Outbound",
        "parentfield": 'outbound_cylinders',
        "parenttype": "Warehouse Withdrawal and Return Slip",
        "parent": checkWWRS[0][0],
        "outbound_customer":customer,
        "outbound_item":delivery_note_item[x].item_name,
        "outbound_qty":delivery_note_item[x].qty,
        "outbound_delivery_note":delivery_note
    }
    print(test_dict)
    test_dict = frappe.get_doc(test_dict)
    test_dict.insert(ignore_permissions=True)

Got an error message: pymysql.err.InternalError: (1054, “Unknown column ‘_seen’ in ‘field list’”)

I am not sure why it is telling me to have ‘_seen’ column but to fix this I had to add a custom field _seen with data type data to the child table.