diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index d1c528847dd4a4ee4108c88349678015af042b2f..73e19e9bcc08bbace865b04e91e9e75a2113094d 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 aeaf8b6aa01ea68d98a58231e1b6dbbd2835042a..a5b29ce8e164968585c14e0379f929f3469d9933 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()