refactor: allow root deletion by default for nested set
* deprecate allow_root_deletion param in on_trash nestedset hook * allowed to turn root deletion off by allow_root_deletion class variable in doctype controller
This commit is contained in:
parent
9c4318028a
commit
42fcf61cae
4 changed files with 8 additions and 29 deletions
|
|
@ -45,7 +45,6 @@
|
|||
"allow_events_in_timeline",
|
||||
"allow_auto_repeat",
|
||||
"make_attachments_public",
|
||||
"allow_root_deletion",
|
||||
"view_settings",
|
||||
"title_field",
|
||||
"show_title_field_in_link",
|
||||
|
|
@ -606,13 +605,6 @@
|
|||
"fieldname": "make_attachments_public",
|
||||
"fieldtype": "Check",
|
||||
"label": "Make Attachments Public by Default"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "is_tree",
|
||||
"fieldname": "allow_root_deletion",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Root Deletion"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-bolt",
|
||||
|
|
|
|||
|
|
@ -13,14 +13,12 @@
|
|||
"search_fields",
|
||||
"column_break_5",
|
||||
"istable",
|
||||
"is_tree",
|
||||
"editable_grid",
|
||||
"quick_entry",
|
||||
"track_changes",
|
||||
"track_views",
|
||||
"allow_auto_repeat",
|
||||
"allow_import",
|
||||
"allow_root_deletion",
|
||||
"fields_section_break",
|
||||
"fields",
|
||||
"naming_section",
|
||||
|
|
@ -339,20 +337,6 @@
|
|||
"fieldname": "make_attachments_public",
|
||||
"fieldtype": "Check",
|
||||
"label": "Make Attachments Public by Default"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_tree",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Tree",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "is_tree",
|
||||
"fieldname": "allow_root_deletion",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Root Deletion"
|
||||
}
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
|
|
|
|||
|
|
@ -570,8 +570,6 @@ doctype_properties = {
|
|||
"default_print_format": "Data",
|
||||
"allow_copy": "Check",
|
||||
"istable": "Check",
|
||||
'is_tree': 'Check',
|
||||
'allow_root_deletion': 'Check',
|
||||
"quick_entry": "Check",
|
||||
"editable_grid": "Check",
|
||||
"max_attachments": "Int",
|
||||
|
|
|
|||
|
|
@ -271,13 +271,18 @@ class NestedSet(Document):
|
|||
update_nsm(self)
|
||||
self.validate_ledger()
|
||||
|
||||
def on_trash(self):
|
||||
def on_trash(self, allow_root_deletion=False):
|
||||
"""
|
||||
Runs on deletion of a document/node
|
||||
|
||||
:param allow_root_deletion: used for allowing root document deletion (DEPRECATED)
|
||||
"""
|
||||
|
||||
if not getattr(self, "nsm_parent_field", None):
|
||||
self.nsm_parent_field = frappe.scrub(self.doctype) + "_parent"
|
||||
|
||||
parent = self.get(self.nsm_parent_field)
|
||||
allow_root_deletion = self.meta.allow_root_deletion
|
||||
if not parent and not allow_root_deletion:
|
||||
if not parent and not getattr(self, "allow_root_deletion", True):
|
||||
frappe.throw(_("Root {0} cannot be deleted").format(_(self.doctype)))
|
||||
|
||||
# cannot delete non-empty group
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue