From cf285284a14e00225cfefa04b2fe1399956f76f0 Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Mon, 7 Apr 2025 20:33:27 +0530 Subject: [PATCH] fix: validate if pos is opened before pos invoice creation (#46907) * fix: validate if pos is opened before pos invoice creation * fix: added title on throw dialog * test: fixed failing test --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 13 +++++++++++++ .../doctype/pos_invoice/test_pos_invoice.py | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index d1c528847dd..73e19e9bcc0 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -197,6 +197,7 @@ class POSInvoice(SalesInvoice): # run on validate method of selling controller super(SalesInvoice, self).validate() + self.validate_pos_opening_entry() self.validate_auto_set_posting_time() self.validate_mode_of_payment() self.validate_uom_is_integer("stock_uom", "stock_qty") @@ -328,6 +329,18 @@ class POSInvoice(SalesInvoice): _("Payment related to {0} is not completed").format(pay.mode_of_payment) ) + def validate_pos_opening_entry(self): + opening_entries = frappe.get_list( + "POS Opening Entry", filters={"pos_profile": self.pos_profile, "status": "Open", "docstatus": 1} + ) + if len(opening_entries) == 0: + frappe.throw( + title=_("POS Opening Entry Missing"), + msg=_("No open POS Opening Entry found for POS Profile {0}.").format( + frappe.bold(self.pos_profile) + ), + ) + def validate_stock_availablility(self): if self.is_return: return diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index aeaf8b6aa01..a5b29ce8e16 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -28,8 +28,11 @@ class TestPOSInvoice(IntegrationTestCase): make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) frappe.db.sql("delete from `tabTax Rule`") - def setUp(self): - frappe.db.commit() + from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile + from erpnext.accounts.doctype.pos_opening_entry.test_pos_opening_entry import create_opening_entry + + cls.test_user, cls.pos_profile = init_user_and_profile() + create_opening_entry(cls.pos_profile, cls.test_user) def tearDown(self): frappe.db.rollback() -- GitLab