From e35e8968f0825256e09b7beba8615270b9559e4d Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Sat, 8 Nov 2025 12:31:40 +0530 Subject: [PATCH] fix: prevent pos opening entry creation for disabled pos profile --- .../doctype/pos_opening_entry/pos_opening_entry.py | 14 ++++++++++++-- .../pos_opening_entry/test_pos_opening_entry.py | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py index d8768055437..3239274035c 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py @@ -43,9 +43,19 @@ class POSOpeningEntry(StatusUpdater): self.set_status() def validate_pos_profile_and_cashier(self): - if self.company != frappe.db.get_value("POS Profile", self.pos_profile, "company"): + if not frappe.db.exists("POS Profile", self.pos_profile): + frappe.throw(_("POS Profile {} does not exist.").format(self.pos_profile)) + + pos_profile_company, pos_profile_disabled = frappe.db.get_value( + "POS Profile", self.pos_profile, ["company", "disabled"] + ) + + if pos_profile_disabled: + frappe.throw(_("POS Profile {} is disabled.").format(frappe.bold(self.pos_profile))) + + if self.company != pos_profile_company: frappe.throw( - _("POS Profile {} does not belongs to company {}").format(self.pos_profile, self.company) + _("POS Profile {} does not belong to company {}").format(self.pos_profile, self.company) ) if not cint(frappe.db.get_value("User", self.user, "enabled")): diff --git a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py index e371e5408fc..2b23f94932f 100644 --- a/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py +++ b/erpnext/accounts/doctype/pos_opening_entry/test_pos_opening_entry.py @@ -40,6 +40,12 @@ class TestPOSOpeningEntry(IntegrationTestCase): self.assertEqual(opening_entry.status, "Open") self.assertNotEqual(opening_entry.docstatus, 0) + def test_pos_opening_entry_on_disabled_pos(self): + test_user, pos_profile = self.init_user_and_profile(disabled=1) + + with self.assertRaises(frappe.ValidationError): + create_opening_entry(pos_profile, test_user.name) + def test_multiple_pos_opening_entries_for_same_pos_profile(self): test_user, pos_profile = self.init_user_and_profile() opening_entry = create_opening_entry(pos_profile, test_user.name)