diff --git a/india_compliance/__init__.py b/india_compliance/__init__.py index 99dda4e6c..88349fdef 100644 --- a/india_compliance/__init__.py +++ b/india_compliance/__init__.py @@ -1,4 +1 @@ __version__ = "15.0.0-dev" - -MIN_FRAPPE_VERSION = "15.0.0-dev" -MIN_ERPNEXT_VERSION = "15.0.0-dev" diff --git a/india_compliance/patches/check_version_compatibility.py b/india_compliance/patches/check_version_compatibility.py index 41830359a..8711b8921 100644 --- a/india_compliance/patches/check_version_compatibility.py +++ b/india_compliance/patches/check_version_compatibility.py @@ -2,20 +2,23 @@ from packaging import version import frappe +from frappe.utils.change_log import get_app_branch import erpnext -from india_compliance import MIN_ERPNEXT_VERSION, MIN_FRAPPE_VERSION +import india_compliance + +IC_VERSION = version.parse(india_compliance.__version__) VERSIONS_TO_COMPARE = [ { - "app_name": "frappe", - "current_version": frappe.__version__, - "required_version": MIN_FRAPPE_VERSION, + "app_name": "Frappe", + "current_version": version.parse(frappe.__version__), + "required_versions": {"version-14": "14.42.0"}, }, { - "app_name": "erpnext", - "current_version": erpnext.__version__, - "required_version": MIN_ERPNEXT_VERSION, + "app_name": "ERPNext", + "current_version": version.parse(erpnext.__version__), + "required_versions": {"version-14": "14.32.0"}, }, ] @@ -23,18 +26,31 @@ def execute(): for app in VERSIONS_TO_COMPARE: app_name = app["app_name"] - current_version = app["current_version"] - required_version = app["required_version"] + app_version = app["current_version"] + + if IC_VERSION.major != app_version.major: + show_error_and_exit( + f"Incompatible {app_name} Version: \nPlease switch to version" + f" {IC_VERSION.major} of {app_name} to use the current version of India" + " Compliance.\n" + ) + + app_branch = get_app_branch(app_name.lower()) + required_versions = app["required_versions"] - if version.parse(current_version) >= version.parse(required_version): + if app_branch not in required_versions: continue - click.secho( - ( - f"Please upgrade {app_name} to version {required_version} or" - " above to use the current version of India Compliance." - ), - fg="red", - ) + required_version = version.parse(required_versions[app_branch]) + + if app_version < required_version: + show_error_and_exit( + f"Incompatible {app_name} Version: \nPlease upgrade {app_name} to" + f" version {required_version} or above to use the current version of" + " India Compliance.\n" + ) + - frappe.throw(f"Incompatible {app_name.title()} Version") +def show_error_and_exit(error_message): + click.secho(error_message, fg="red") + raise SystemExit(1)