test: flag an SLE whose balance is out of sync with the FIFO queue

This commit is contained in:
Nabin Hait
2026-07-01 19:29:16 +05:30
parent 04617b40b4
commit 875fc72842

View File

@@ -28,6 +28,29 @@ class TestFifoQueueVsQtyAfterTransactionComparison(ERPNextTestSuite):
item_codes = [row.get("item_code") for row in data if row]
self.assertNotIn(item, item_codes)
def test_queue_out_of_sync_is_flagged(self):
item = "_Test Item 2"
warehouse = "Stores - _TC"
frappe.db.set_value("Item", item, "valuation_method", "FIFO")
entry = make_stock_entry(
item_code=item, to_warehouse=warehouse, qty=10, rate=100, posting_date="2026-06-01"
)
sle = frappe.db.get_value(
"Stock Ledger Entry",
{"voucher_no": entry.name, "item_code": item, "warehouse": warehouse},
"name",
)
# corrupt the running balance so it no longer matches the FIFO queue (the queue holds 10,
# but the stored qty_after_transaction now claims 7)
frappe.db.set_value("Stock Ledger Entry", sle, "qty_after_transaction", 7, update_modified=False)
data = self.run_report({"company": "_Test Company", "item_code": item, "warehouse": warehouse})
flagged = {row.get("name") for row in data if row}
self.assertIn(sle, flagged)
def test_requires_a_filter(self):
with self.assertRaises(frappe.ValidationError):
self.run_report({"company": "_Test Company"})