|
|
@@ -194,11 +194,7 @@ class NestedSet(Document): |
|
|
|
frappe.throw(_("Root {0} cannot be deleted").format(_(self.doctype))) |
|
|
|
|
|
|
|
# cannot delete non-empty group |
|
|
|
has_children = frappe.db.sql("""select count(name) from `tab{doctype}` |
|
|
|
where `{nsm_parent_field}`=%s""".format(doctype=self.doctype, nsm_parent_field=self.nsm_parent_field), |
|
|
|
(self.name,))[0][0] |
|
|
|
if has_children: |
|
|
|
frappe.throw(_("Cannot delete {0} as it has child nodes").format(self.name), NestedSetChildExistsError) |
|
|
|
self.validate_if_child_exists() |
|
|
|
|
|
|
|
self.set(self.nsm_parent_field, "") |
|
|
|
|
|
|
@@ -211,6 +207,13 @@ class NestedSet(Document): |
|
|
|
else: |
|
|
|
raise |
|
|
|
|
|
|
|
def validate_if_child_exists(self): |
|
|
|
has_children = frappe.db.sql("""select count(name) from `tab{doctype}` |
|
|
|
where `{nsm_parent_field}`=%s""".format(doctype=self.doctype, nsm_parent_field=self.nsm_parent_field), |
|
|
|
(self.name,))[0][0] |
|
|
|
if has_children: |
|
|
|
frappe.throw(_("Cannot delete {0} as it has child nodes").format(self.name), NestedSetChildExistsError) |
|
|
|
|
|
|
|
def before_rename(self, olddn, newdn, merge=False, group_fname="is_group"): |
|
|
|
if merge and hasattr(self, group_fname): |
|
|
|
is_group = frappe.db.get_value(self.doctype, newdn, group_fname) |
|
|
@@ -237,7 +240,7 @@ class NestedSet(Document): |
|
|
|
frappe.throw(_("""Multiple root nodes not allowed."""), NestedSetMultipleRootsError) |
|
|
|
|
|
|
|
def validate_ledger(self, group_identifier="is_group"): |
|
|
|
if self.get(group_identifier) == "No": |
|
|
|
if hasattr(self, group_identifier) and not bool(self.get(group_identifier)): |
|
|
|
if frappe.db.sql("""select name from `tab{0}` where {1}=%s and docstatus!=2""" |
|
|
|
.format(self.doctype, self.nsm_parent_field), (self.name)): |
|
|
|
frappe.throw(_("{0} {1} cannot be a leaf node as it has children").format(_(self.doctype), self.name)) |
|
|
|