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(