8000 fix: improve delete_contact_and_address (backport #20381) by mergify[bot] · Pull Request #21280 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: improve delete_contact_and_address (backport #20381) #21280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions frappe/contacts/address_and_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,26 @@ def get_permitted_and_not_permitted_links(doctype):
return {"permitted_links": permitted_links, "not_permitted_links": not_permitted_links}


def delete_contact_and_address(doctype, docname):
def delete_contact_and_address(doctype: str, docname: str) -> None:
for parenttype in ("Contact", "Address"):
items = frappe.db.sql_list(
"""select parent from `tabDynamic Link`
where parenttype=%s and link_doctype=%s and link_name=%s""",
(parenttype, doctype, docname),
)

for name in items:
for name in frappe.get_all(
"Dynamic Link",
filters={
"parenttype": parenttype,
"link_doctype": doctype,
"link_name": docname,
},
pluck="parent",
):
doc = frappe.get_doc(parenttype, name)
if len(doc.links) == 1:
doc.delete()
else:
for link in doc.links:
if link.link_doctype == doctype and link.link_name == docname:
doc.remove(link)
doc.save()
break


@frappe.whitelist()
Expand Down
0