fix(frappe.client): delete child doc via parent

so that parent's on_update is called
no change for deletion of normal doctype
This commit is contained in:
Faris Ansari 2022-10-18 01:23:37 +05:30
parent 4f650854b8
commit 55bc60433f

View file

@ -270,7 +270,7 @@ def delete(doctype, name):
:param doctype: DocType of the document to be deleted
:param name: name of the document to be deleted"""
frappe.delete_doc(doctype, name, ignore_missing=False)
delete_doc(doctype, name)
@frappe.whitelist(methods=["POST", "PUT"])
@ -462,3 +462,23 @@ def insert_doc(doc) -> "Document":
return parent
return frappe.get_doc(doc).insert()
def delete_doc(doctype, name):
"""Deletes document
if doctype is a child table, then deletes the child record using the parent doc
so that the parent doc's `on_update` is called
"""
if frappe.is_table(doctype):
parenttype, parent, parentfield = frappe.db.get_value(
doctype, name, ["parenttype", "parent", "parentfield"]
)
parent = frappe.get_doc(parenttype, parent)
for row in parent.get(parentfield):
if row.name == name:
parent.remove(row)
parent.save()
break
else:
frappe.delete_doc(doctype, name, ignore_missing=False)