From 87e8305753d5c26371dfa6b0ad73891c3973e22d Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Fri, 7 Nov 2025 16:03:04 +0530 Subject: [PATCH] feat(pos): prevent disabling POS Profile when open POS sessions exist (cherry picked from commit c5219278fb379de6f635a487de7f0db3bb8b6e55) --- .../accounts/doctype/pos_profile/pos_profile.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index 143407eb750..2928782a647 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -70,6 +70,7 @@ class POSProfile(Document): # end: auto-generated types def validate(self): + self.validate_disabled() self.validate_default_profile() self.validate_all_link_fields() self.validate_duplicate_groups() @@ -94,6 +95,21 @@ class POSProfile(Document): title=_("Mandatory Accounting Dimension"), ) + def validate_disabled(self): + old_doc = self.get_doc_before_save() + + if ( + old_doc + and self.disabled + and old_doc.disabled != self.disabled + and frappe.db.exists("POS Opening Entry", {"pos_profile": self.name, "status": "Open"}) + ): + frappe.throw( + _("POS Profile {0} cannot be disabled as there are ongoing POS sessions.").format( + frappe.bold(self.name) + ) + ) + def validate_default_profile(self): for row in self.applicable_for_users: res = frappe.db.sql(