Created
March 17, 2025 13:45
-
-
Save ManotLuijiu/14d984469e27fc42b3d025dab7735d0a to your computer and use it in GitHub Desktop.
print_designer uninstall.py (new)
This file contains hidden or 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
import frappe | |
def before_uninstall(): | |
# Remove Print Format record | |
if frappe.db.exists("Print Format", "Print Designer"): | |
frappe.delete_doc("Print Format", "Print Designer") | |
# Remove Print Designer entries from property setter | |
property_setters = frappe.get_all( | |
"Property Setter", | |
filters={ | |
"property": "default_print_format", | |
"value": "Print Designer" | |
} | |
) | |
for property_setter in property_setters: | |
frappe.delete_doc("Property Setter", property_setter.name) | |
# Try to safely remove pdf_generator option | |
try: | |
remove_pdf_generator_option() | |
except Exception: | |
# If it fails, just log it and continue | |
frappe.log_error("Failed to remove pdf_generator option, but continuing uninstallation") | |
def remove_pdf_generator_option(): | |
try: | |
set_pdf_generator_option("remove") | |
except Exception: | |
# If it fails, continue with uninstallation | |
pass | |
def set_pdf_generator_option(action): | |
try: | |
field = frappe.get_meta("Print Format").get_field("pdf_generator") | |
if not field: | |
return | |
options = (field.options or "").split("\n") | |
if action == "add": | |
if "Print Designer" not in options: | |
options.append("Print Designer") | |
elif action == "remove": | |
if "Print Designer" in options: | |
options.remove("Print Designer") | |
# Update options | |
frappe.db.set_value( | |
"DocField", | |
{"parent": "Print Format", "fieldname": "pdf_generator"}, | |
"options", | |
"\n".join(options), | |
) | |
except Exception: | |
# Safely handle any errors | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment