How to add row to child table of submitted doc

I have doctype “MYDOCTYPE” it has child table “MYCHILD TABLE” and i submitted the doc and i want to update the child table of MYDOCTYPE when ever i submit payment entry.

in payment entry i wrote this code in payment entry on submit function

if self.references:
			for reference in self.references:
				if reference.reference_doctype == "MY DOCTYPE":
					ohb = frappe.get_doc("MY DOCTYPE",reference.reference_name)
					if not ohb.update_dueamount(reference.reference_name,reference.allocated_amount,self.paid_amount, :
						frappe.throw("Paid Amount Is Greater Than Due Amount Of Hotel")

in MY doctype i wrote function update_dueamount

            		oph = frappe.get_doc("MY DOCTYPE",
			'payment_no'     		:payment_no,
			'date_of_payment'		:today(),
			'paid_amount'	 		:amount_paid,
			'out_standing_amount'	:due_amount,
			'reference_name'		:"Payment Entry"

but when ever i submit payment entry i got this error


and i also tried this in update dueamount

		oph = frappe.new_doc("Payment History")
		oph.payment_no  		= payment_no
		oph.parent      		= hotel_booking
		oph.parentfield 		= "my_childtable"
		oph.parenttype  		= "MY DOCTYPE"
		oph.paid_amount 		= amount_paid
		oph.out_standing_amount = due_amount
		oph.date_of_payment     = today()

but after submitting payment entry i get this

when ever i submit payment entry i get 1 for every row number instead of incrementing

can any one please help me

With this aproach you will need to increment the idx property manually. So, if you want it to be at the bottom, then it should be equals to len(doc.items) + 1

1 Like