-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove custom fields on uninstall
- Loading branch information
1 parent
c177b1f
commit 3217782
Showing
3 changed files
with
50 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import click | ||
|
||
import frappe | ||
|
||
from lending.install import LOAN_CUSTOM_FIELDS | ||
|
||
|
||
def before_uninstall(): | ||
try: | ||
print("Removing customizations created by the Frappe Lending app...") | ||
delete_custom_fields(LOAN_CUSTOM_FIELDS) | ||
|
||
except Exception as e: | ||
BUG_REPORT_URL = "https://github.com/frappe/lending/issues/new" | ||
click.secho( | ||
"Removing Customizations for Frappe Lending failed due to an error." | ||
" Please try again or" | ||
f" report the issue on {BUG_REPORT_URL} if not resolved.", | ||
fg="bright_red", | ||
) | ||
raise e | ||
|
||
click.secho("Frappe Lending app customizations have been removed successfully.", fg="green") | ||
|
||
|
||
def delete_custom_fields(custom_fields): | ||
""" | ||
:param custom_fields: a dict like `{'Customer': [{fieldname: 'test', ...}]}` | ||
""" | ||
|
||
for doctypes, fields in custom_fields.items(): | ||
if isinstance(fields, dict): | ||
# only one field | ||
fields = [fields] | ||
|
||
if isinstance(doctypes, str): | ||
# only one doctype | ||
doctypes = (doctypes,) | ||
|
||
for doctype in doctypes: | ||
frappe.db.delete( | ||
"Custom Field", | ||
{ | ||
"fieldname": ("in", [field["fieldname"] for field in fields]), | ||
"dt": doctype, | ||
}, | ||
) | ||
|
||
frappe.clear_cache(doctype=doctype) |