瀏覽代碼

[fix] dynamic link checking during cancel

version-14
Anand Doshi 10 年之前
父節點
當前提交
ac2312e9ab
共有 2 個檔案被更改,包括 22 行新增8 行删除
  1. +21
    -7
      frappe/model/delete_doc.py
  2. +1
    -1
      frappe/model/document.py

+ 21
- 7
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`


+ 1
- 1
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):


Loading…
取消
儲存