diff --git a/crm/hooks.py b/crm/hooks.py index 8e703a15..b8bc1e99 100644 --- a/crm/hooks.py +++ b/crm/hooks.py @@ -76,7 +76,7 @@ after_install = "crm.install.after_install" # Uninstallation # ------------ -# before_uninstall = "crm.uninstall.before_uninstall" +before_uninstall = "crm.uninstall.before_uninstall" # after_uninstall = "crm.uninstall.after_uninstall" # Integration Setup diff --git a/crm/install.py b/crm/install.py index ff8a914d..351dd8ce 100644 --- a/crm/install.py +++ b/crm/install.py @@ -1,9 +1,11 @@ # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors # MIT License. See license.txt - from __future__ import unicode_literals +import click import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields + def before_install(): pass @@ -12,6 +14,7 @@ def after_install(): add_default_deal_statuses() add_default_communication_statuses() add_property_setter() + add_email_template_custom_fields() frappe.db.commit() def add_default_lead_statuses(): @@ -113,4 +116,31 @@ def add_property_setter(): doc.property = "search_fields" doc.property_type = "Data" doc.value = "email_id" - doc.insert() \ No newline at end of file + doc.insert() + +def add_email_template_custom_fields(): + if not frappe.get_meta("Email Template").has_field("enabled"): + click.secho("* Installing Custom Fields in Email Template") + + create_custom_fields( + { + "Email Template": [ + { + "default": "0", + "fieldname": "enabled", + "fieldtype": "Check", + "label": "Enabled", + "insert_after": "", + }, + { + "fieldname": "reference_doctype", + "fieldtype": "Link", + "label": "Doctype", + "options": "DocType", + "insert_after": "enabled", + }, + ] + } + ) + + frappe.clear_cache(doctype="Email Template") diff --git a/crm/uninstall.py b/crm/uninstall.py new file mode 100644 index 00000000..34622d0b --- /dev/null +++ b/crm/uninstall.py @@ -0,0 +1,22 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt +from __future__ import unicode_literals +import click +import frappe + +def before_uninstall(): + delete_email_template_custom_fields() + +def delete_email_template_custom_fields(): + if frappe.get_meta("Email Template").has_field("enabled"): + click.secho("* Uninstalling Custom Fields from Email Template") + + fieldnames = ( + "enabled", + "reference_doctype", + ) + + for fieldname in fieldnames: + frappe.db.delete("Custom Field", {"name": "Email Template-" + fieldname}) + + frappe.clear_cache(doctype="Email Template") \ No newline at end of file