fix: don't allow deleting original doc if amendment exists
This commit is contained in:
parent
178b699466
commit
b51a479fc2
2 changed files with 16 additions and 1 deletions
|
|
@ -254,7 +254,7 @@ def check_if_doc_is_linked(doc, method="Delete"):
|
|||
|
||||
for lf in link_fields:
|
||||
link_dt, link_field, issingle = lf["parent"], lf["fieldname"], lf["issingle"]
|
||||
if link_dt in ignored_doctypes or link_field == "amended_from":
|
||||
if link_dt in ignored_doctypes or (link_field == "amended_from" and method == "Cancel"):
|
||||
continue
|
||||
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class TestLinkedWith(FrappeTestCase):
|
|||
def tearDown(self):
|
||||
for doctype in ["Parent DocType", "Child DocType1", "Child DocType2"]:
|
||||
frappe.delete_doc("DocType", doctype)
|
||||
frappe.db.commit()
|
||||
|
||||
def test_get_doctype_references_by_link_field(self):
|
||||
references = linked_with.get_references_across_doctypes_by_link_field(
|
||||
|
|
@ -139,3 +140,17 @@ class TestLinkedWith(FrappeTestCase):
|
|||
child_record.cancel()
|
||||
child_record.delete()
|
||||
parent_record.delete()
|
||||
|
||||
def test_check_delete_integrity(self):
|
||||
"""Don't allow deleting cancelled document if amendment exists"""
|
||||
doc = frappe.get_doc({"doctype": "Parent DocType"}).insert()
|
||||
doc.submit()
|
||||
doc.cancel()
|
||||
|
||||
amendment = frappe.copy_doc(doc)
|
||||
amendment.amended_from = doc.name
|
||||
amendment.docstatus = 0
|
||||
amendment.insert()
|
||||
amendment.submit()
|
||||
|
||||
self.assertRaises(frappe.LinkExistsError, doc.delete)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue