test: fix POS Closing Entry Test
- Separated into two tests, one checks if SI cancelling is blocked, the other checks PCE cancel impact
- This is done because after cancel via assertRaises, damage done by cancel still exists or is partially comitted
- Dont use this partially cancelled doc for any assertions further, end test at exception assertion
- Use `get_value` to check SI docstatus, as its primary key changes after cancel
diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
index b596c0c..0265f43 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
+++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
@@ -19,6 +19,7 @@
def tearDown(self):
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
+ frappe.db.rollback()
def test_pos_closing_entry(self):
test_user, pos_profile = init_user_and_profile()
@@ -50,7 +51,8 @@
self.assertEqual(pcv_doc.total_quantity, 2)
self.assertEqual(pcv_doc.net_total, 6700)
- def test_cancelling_of_pos_closing_entry(self):
+ def test_cancelling_of_consolidated_sales_invoice(self):
+ "Check if cancelling consolidated Sales Invoice with submitted POS Closing Entry is blocked."
test_user, pos_profile = init_user_and_profile()
opening_entry = create_opening_entry(pos_profile, test_user.name)
@@ -83,13 +85,46 @@
si_doc = frappe.get_doc("Sales Invoice", pos_inv1.consolidated_invoice)
self.assertRaises(frappe.ValidationError, si_doc.cancel)
+ def test_cancelling_of_pos_closing_entry(self):
+ "Check impact of cancelling POS Closing Entry."
+ test_user, pos_profile = init_user_and_profile()
+ opening_entry = create_opening_entry(pos_profile, test_user.name)
+
+ pos_inv1 = create_pos_invoice(rate=3500, do_not_submit=1)
+ pos_inv1.append('payments', {
+ 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3500
+ })
+ pos_inv1.submit()
+
+ pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1)
+ pos_inv2.append('payments', {
+ 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3200
+ })
+ pos_inv2.submit()
+
+ pcv_doc = make_closing_entry_from_opening(opening_entry)
+ payment = pcv_doc.payment_reconciliation[0]
+
+ for d in pcv_doc.payment_reconciliation:
+ if d.mode_of_payment == 'Cash':
+ d.closing_amount = 6700
+
+ pcv_doc.submit()
+
+ pos_inv1.load_from_db()
+ si_name = pos_inv1.consolidated_invoice
+
pcv_doc.load_from_db()
pcv_doc.cancel()
- si_doc.load_from_db()
pos_inv1.load_from_db()
- self.assertEqual(si_doc.docstatus, 2)
- self.assertEqual(pos_inv1.status, 'Paid')
+ # After POS Closing Entry cancel, SI doc gets cancelled, unlinked and renamed
+ # There's no reference doc to fetch SI with new cancelled name
+ # which is why we are hardcoding suffix
+ si_docstatus = frappe.db.get_value("Sales Invoice", si_name+"-CANC-0", "docstatus")
+ self.assertEqual(si_docstatus, 2)
+ self.assertEqual(pos_inv1.status, 'Paid')
+ self.assertIsNone(pos_inv1.consolidated_invoice)
def init_user_and_profile(**args):
user = 'test@example.com'