From ac2312e9ab37ec7efb9fb1da15f8f98fe8c2002f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 14 Aug 2015 12:48:55 +0530 Subject: [PATCH 1/2] [fix] dynamic link checking during cancel --- frappe/model/delete_doc.py | 28 +++++++++++++++++++++------- frappe/model/document.py | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index 3cedda56b5..a0e795007d 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -150,27 +150,41 @@ def check_if_doc_is_linked(doc, method="Delete"): if item and item.parent != doc.name and ((method=="Delete" and item.docstatus<2) or (method=="Cancel" and item.docstatus==1)): + # raise exception only if + # linked to an non-cancelled doc when deleting + # or linked to a submitted doc when cancelling frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}").format(doc.doctype, doc.name, item.parenttype if item.parent else link_dt, item.parent or item.name), frappe.LinkExistsError) -def check_if_doc_is_dynamically_linked(doc): +def check_if_doc_is_dynamically_linked(doc, method="Delete"): for query in dynamic_link_queries: for df in frappe.db.sql(query, as_dict=True): if frappe.get_meta(df.parent).issingle: # dynamic link in single doc refdoc = frappe.db.get_singles_dict(df.parent) - if refdoc.get(df.options)==doc.doctype and refdoc.get(df.fieldname)==doc.name: + if (refdoc.get(df.options)==doc.doctype + and refdoc.get(df.fieldname)==doc.name + and ((method=="Delete" and refdoc.docstatus < 2) + or (method=="Cancel" and refdoc.docstatus==1)) + ): + # raise exception only if + # linked to an non-cancelled doc when deleting + # or linked to a submitted doc when cancelling frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}").format(doc.doctype, doc.name, df.parent, ""), frappe.LinkExistsError) else: - # dynamic link in table - for name in frappe.db.sql_list("""select name from `tab{parent}` where - {options}=%s and {fieldname}=%s""".format(**df), (doc.doctype, doc.name)): - frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}").format(doc.doctype, - doc.name, df.parent, name), frappe.LinkExistsError) + for refdoc in frappe.db.sql("""select name, docstatus from `tab{parent}` where + {options}=%s and {fieldname}=%s""".format(**df), (doc.doctype, doc.name), as_dict=True): + + if ((method=="Delete" and refdoc.docstatus < 2) or (method=="Cancel" and refdoc.docstatus==1)): + # raise exception only if + # linked to an non-cancelled doc when deleting + # or linked to a submitted doc when cancelling + frappe.throw(_("Cannot delete or cancel because {0} {1} is linked with {2} {3}")\ + .format(doc.doctype, doc.name, df.parent, refdoc.name), frappe.LinkExistsError) def delete_linked_todos(doc): delete_doc("ToDo", frappe.db.sql_list("""select name from `tabToDo` diff --git a/frappe/model/document.py b/frappe/model/document.py index 6a5ddd0654..823b98c228 100644 --- a/frappe/model/document.py +++ b/frappe/model/document.py @@ -581,7 +581,7 @@ class Document(BaseDocument): from frappe.model.delete_doc import check_if_doc_is_linked, check_if_doc_is_dynamically_linked if not self.flags.ignore_links: check_if_doc_is_linked(self, method="Cancel") - check_if_doc_is_dynamically_linked(self) + check_if_doc_is_dynamically_linked(self, method="Cancel") @staticmethod def whitelist(f): From 464050bfbf580ed32c24c95cd25cd65b4c126219 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 14 Aug 2015 13:27:40 +0600 Subject: [PATCH 2/2] bumped to version 5.4.1 --- frappe/__version__.py | 2 +- frappe/hooks.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/__version__.py b/frappe/__version__.py index c32bebc81a..2bcefd9d49 100644 --- a/frappe/__version__.py +++ b/frappe/__version__.py @@ -1,2 +1,2 @@ from __future__ import unicode_literals -__version__ = "5.4.0" +__version__ = "5.4.1" diff --git a/frappe/hooks.py b/frappe/hooks.py index c3ef9a7f44..bab4d141fb 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -26,7 +26,7 @@ to ERPNext. """ app_icon = "octicon octicon-circuit-board" -app_version = "5.4.0" +app_version = "5.4.1" app_color = "orange" github_link = "https://github.com/frappe/frappe" diff --git a/setup.py b/setup.py index 43473c298c..9a6a22b706 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = "5.4.0" +version = "5.4.1" with open("requirements.txt", "r") as f: install_requires = f.readlines()