How to add value to read only child table

Hi,
I have created doctype

My Doctype

it has child table

My Chidtable

which is read only

but when ever i submit this i want to add some details to My Childtable

what i have tried is

def before_submit(self):
    		self.my_child_table.append({
		"payment_no"  :"XYZ",
		"paid_amount" : self.amount_paid,
		"out_standing_amount":self.due_amount,
		"paid_amount": self.amount_paid,
		"date_of_payment": today()
		})

but when ever i submitt i get this error

  File "/home/shahid/think/frappe-think/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 725, in submit
    self._submit()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 714, in _submit
    self.save()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 223, in save
    return self._save(*args, **kwargs)
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 255, in _save
    self._validate()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 384, in _validate
    self._validate_mandatory()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 590, in _validate_mandatory
    missing.extend(d._get_missing_mandatory_fields())
AttributeError: 'dict' object has no attribute '_get_missing_mandatory_fields'

Traceback (most recent call last):
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/app.py", line 55, in application
    response = frappe.handler.handle()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/handler.py", line 40, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/__init__.py", line 898, in call
    return fn(*args, **newargs)
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 725, in submit
    self._submit()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 714, in _submit
    self.save()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 223, in save
    return self._save(*args, **kwargs)
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 255, in _save
    self._validate()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 384, in _validate
    self._validate_mandatory()
  File "/home/shahid/think/frappe-think/apps/frappe/frappe/model/document.py", line 590, in _validate_mandatory
    missing.extend(d._get_missing_mandatory_fields())
AttributeError: 'dict' object has no attribute '_get_missing_mandatory_fields'```


please help me to resolve the error

data = {
“payment_no” :“XYZ”,
“paid_amount” : self.amount_paid,
“out_standing_amount”:self.due_amount,
“paid_amount”: self.amount_paid,
“date_of_payment”: today()
}
self.update( {
“my_child_table” : [data]
} )

Hopefully this works !

Did you manage? I have a similar scenario to work on.

This replaces all data

My solution:

	self.childdoc = []
	data = []
	for loop
		data.append({
			"item": item.name,
			"quantity": quantity or 0,
			"amount": (quantity * item.price) or 0
		})
	self.update({
		"childdoc": data
	})

Hope it helps others.

1 Like