diff --git a/payments/hooks.py b/payments/hooks.py index 84448fc..024a01b 100644 --- a/payments/hooks.py +++ b/payments/hooks.py @@ -63,7 +63,7 @@ app_license = "MIT" # Installation # ------------ -# before_install = "pay.install.before_install" +before_install = "payments.utils.before_install" after_install = "payments.utils.make_custom_fields" # Uninstallation diff --git a/payments/utils/__init__.py b/payments/utils/__init__.py index e038119..518a939 100644 --- a/payments/utils/__init__.py +++ b/payments/utils/__init__.py @@ -1,6 +1,7 @@ from payments.utils.utils import ( - get_payment_gateway_controller, + before_install, create_payment_gateway, - make_custom_fields, delete_custom_fields, + get_payment_gateway_controller, + make_custom_fields, ) diff --git a/payments/utils/utils.py b/payments/utils/utils.py index 455065f..a34c16d 100644 --- a/payments/utils/utils.py +++ b/payments/utils/utils.py @@ -2,6 +2,7 @@ import click import frappe from frappe import _ +from frappe.utils.data import cint from frappe.custom.doctype.custom_field.custom_field import create_custom_fields @@ -133,6 +134,8 @@ def make_custom_fields(): ] }) + frappe.clear_cache(doctype="Web Form") + def delete_custom_fields(): if frappe.get_meta("Web Form").has_field("payments_tab"): @@ -156,3 +159,11 @@ def delete_custom_fields(): "Custom Field", {"name": "Web Form-" + fieldname} ) + + frappe.clear_cache(doctype="Web Form") + + +def before_install(): + # only install for v14 + if cint(frappe.get_module("frappe").__version__[:2]) < 14 or not frappe.get_meta("Module Def").has_field("custom"): + return False