I noticed that we cannot add permissions on Child Doctypes in ERP Next by going to the permission manager. Is there any other way of doing it like using a script? I tried the following in the picture but I’m getting this error “TypeError: ‘NoneType’ object is not callable”
Below is my code and the error is coming from line 19
Is Dependants a child table linked with doctype Member?
ok…you can modify my code for your requirements.
dependent_list is field name for Dependant child table in doctype Patient.
import frappe
import json
from frappe.utils import cstr
def gen_response(status,message,data=[]):
frappe.response['status_code'] = status
frappe.response['message'] = message
frappe.response['data'] = data
@frappe.whitelist()
def update_patient_dependent(patient,dependent_list):
try:
data = json.loads(patient)
if not data.get("name"):
gen_response(400, "Insufficient Param Passed")
elif not frappe.db.exists("Patient", data.get("name")):
gen_response(404, "Invalid Patient ID")
else:
doc = frappe.get_doc("Patient", data.get("name"))
if dependent_list:
doc.dependent_list = []
for dependent_list in json.loads(dependent_list):
doc.append("dependent_list",
{"relative_name" : dependent_list.get('relative_name'),
"relation" : dependent_list.get('relation'),
"description" : dependent_list.get('description'),
"mobile" : dependent_list.get('mobile')}
)
doc.save(ignore_permissions=True)
gen_response(200, "Patient Dependent Updated Successfully")
except frappe.MandatoryError as e:
doc = frappe.new_doc("Patient")
mandatory_fields = e.args[0].split(':')[1].split(',')
mandatory_fields = [doc.meta.get_label(
field.strip()) for field in mandatory_fields]
message = "Could not update Patient due to the following missing mandatory field(s):" + \
" "
message += "" + ",".join(mandatory_fields)
frappe.log_error(frappe.get_traceback())
gen_response(500, message)
except frappe.PermissionError as e:
gen_response(403, "Not Permitted")
except Exception as e:
frappe.log_error(frappe.get_traceback())
gen_response(500, cstr(e))
Thanks very much, it worked