diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index a8a733ac42c..6933b04d2e1 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -196,6 +196,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") @@ -320,6 +321,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 09c9443bdd9..cfe805be4ce 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -26,6 +26,12 @@ class TestPOSInvoice(unittest.TestCase): make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item", qty=800, basic_rate=100) frappe.db.sql("delete from `tabTax Rule`") + 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): if frappe.session.user != "Administrator": frappe.set_user("Administrator")