From 9f3dd7eabd0e6d4b88f71dbf564c6cd92d818bdf Mon Sep 17 00:00:00 2001 From: AarDG10 Date: Mon, 24 Aug 2026 11:08:51 +0530 Subject: [PATCH] fix(company): throw if linked to demo_company field Throws an error msg if user is deleting demo company directly. (cherry picked from commit aaa3100efc8587d7604c6794d3535a828672f70f) --- erpnext/setup/doctype/company/company.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index e08ac8d7fd4..d481bcb0ab1 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -758,6 +758,13 @@ class Company(NestedSet): """ Trash accounts and cost centers for this company if no gl entry exists """ + if frappe.db.get_single_value("Global Defaults", "demo_company") == self.name: + frappe.throw( + _("{0} is the site's Demo Company and cannot be deleted directly. Use {1} instead.").format( + bold(self.name), bold(_("Delete Demo Data")) + ) + ) + NestedSet.validate_if_child_exists(self) frappe.utils.nestedset.update_nsm(self)