Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom fields not being removed on app uninstallation (#278) #279

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions it_management/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
# before_install = "it_management.install.before_install"
# after_install = "it_management.install.after_install"

# Uninstalatiom

before_uninstall = "it_management.it_management.server_script.delete_custom_fields.delete_custom_fields"

# Desk Notifications
# ------------------
# See frappe.core.notifications.get_notification_config
Expand Down
47 changes: 47 additions & 0 deletions it_management/it_management/server_script/delete_custom_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import frappe

def delete_custom_fields():
custom_fields = {
"Task": [
"it_landscape",
"customer",
"user_account",
"configuration_item",
"github_sync_id",
"it_management_table",
"section_break_42"
],
"Delivery Note": ["issue"],
"Issue": [
"it_landscape",
"filter_based_on_customer",
"full_customer_name",
"task",
"contact_html",
"configuration_item",
"it_management_table",
"section_break_43"
],
"Maintenance Schedule" : [
"it_management_table",
"section_break_9"
],
"IT Service Report" : [
"employee_name"
],
"Project" : [
"it_landscape",
"customer_name",
"configuration_item",
"github_sync_id"
]
}

for doctype, fields in custom_fields.items():
for fieldname in fields:
custom_field_name = f"{doctype}-{fieldname}"
try:
frappe.delete_doc("Custom Field", custom_field_name, force=True)
print(f"Custom Field {custom_field_name} deleted")
except frappe.DoesNotExistError:
print(f"Custom Field {custom_field_name} does not exist")