Skip to content

Commit

Permalink
fix(frappe.client): delete child doc via parent
Browse files Browse the repository at this point in the history
so that parent's on_update is called
no change for deletion of normal doctype

(cherry picked from commit 55bc604)
  • Loading branch information
netchampfaris authored and mergify[bot] committed Oct 18, 2022
1 parent a4b88f2 commit 8806eae
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion frappe/client.py
Expand Up @@ -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"])
Expand Down Expand Up @@ -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)

0 comments on commit 8806eae

Please sign in to comment.