test: Invoice status on Cr/Dr note cancellation
diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
index d7a73f0..89240ac 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
@@ -591,6 +591,66 @@
self.assertEqual(si.status, "Paid")
self.assertEqual(si.outstanding_amount, 0)
+ def test_invoice_status_after_cr_note_cancellation(self):
+ # This test case is made after the 'always standalone Credit/Debit notes' feature is introduced
+ transaction_date = nowdate()
+ amount = 100
+
+ si = self.create_sales_invoice(qty=1, rate=amount, posting_date=transaction_date)
+
+ cr_note = self.create_sales_invoice(
+ qty=-1, rate=amount, posting_date=transaction_date, do_not_save=True, do_not_submit=True
+ )
+ cr_note.is_return = 1
+ cr_note.return_against = si.name
+ cr_note = cr_note.save().submit()
+
+ pr = self.create_payment_reconciliation()
+
+ pr.get_unreconciled_entries()
+ invoices = [x.as_dict() for x in pr.get("invoices")]
+ payments = [x.as_dict() for x in pr.get("payments")]
+ pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
+ pr.reconcile()
+
+ pr.get_unreconciled_entries()
+ self.assertEqual(pr.get("invoices"), [])
+ self.assertEqual(pr.get("payments"), [])
+
+ journals = frappe.db.get_all(
+ "Journal Entry",
+ filters={
+ "is_system_generated": 1,
+ "docstatus": 1,
+ "voucher_type": "Credit Note",
+ "reference_type": si.doctype,
+ "reference_name": si.name,
+ },
+ pluck="name",
+ )
+ self.assertEqual(len(journals), 1)
+
+ # assert status outstanding
+ si.reload()
+ self.assertEqual(si.status, "Credit Note Issued")
+ self.assertEqual(si.outstanding_amount, 0)
+
+ cr_note.reload()
+ cr_note.cancel()
+ # 'Credit Note' Journal should be auto cancelled
+ journals = frappe.db.get_all(
+ "Journal Entry",
+ filters={
+ "is_system_generated": 1,
+ "docstatus": 1,
+ "voucher_type": "Credit Note",
+ "reference_type": si.doctype,
+ "reference_name": si.name,
+ },
+ pluck="name",
+ )
+ self.assertEqual(len(journals), 0)
+
def test_cr_note_partial_against_invoice(self):
transaction_date = nowdate()
amount = 100