How to add data to child table using logic

I have a doctype A it has child table CA which is read only i want to add data to child table CA when ever A is submitted

what i tried is

       def before_submit(self):

   	def add_to_payment_history(self,hotel_booking,amount_paid,due_amount,payment_no):
		oph = frappe.new_doc("CA")
		oph.payment_no  		= payment_no
		oph.parent      		= hotel_booking
		oph.parentfield 		= "c_a"
		oph.parenttype  		= "A"
		oph.paid_amount 		= amount_paid
		oph.out_standing_amount = due_amount
		oph.date_of_payment     = today()

where is

		ge.posting_date 		 		= today()
		ge.account       		 		= account
		ge.account_currency      	  	= self.company_currency
		ge.against  					= account
		ge.against_voucher_type         = self.doctype
		ge.against_voucher 				=
		ge.voucher_type                 = self.doctype
		ge.voucher_no                 	=
		ge.is_opening                   = 'No'
		ge.is_advance                   = 'No'
		ge.cost_center               	= self.cost_center
		if account_type == "expense":
			ge.debit        		 	  	= self.total_amount
			ge.debit_in_account_currency 	= self.total_amount
		if account_type == "liablity":
			if self.amount_paid:
				amount = self.total_amount - self.amount_paid
				amount = self.total_amount   = amount
			ge.credit_in_account_currency 	= amount
			ge.party_type = "Supplier"       = self.hotel
		if account_type == "cash": = self.amount_paid
			ge.credit_in_account_currency  = self.amount_paid
		ge.flags.ignore_permissions = True

but when i try to submit form submited but this data is not added to child table CA

please help me to find what is the issue

So restructure your code and assuming that your Child table name in Parent is ‘payment_history’ you should do

def before_submit(self):
  self.payment_history.append( 'payment_history', {
   'doctype': 'CA', 
   'paid_amount': ... 

@shahid_ecit please share the use case too!