From 527765001c528d868dad129d22e716db1220a355 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 1 Jul 2026 19:27:56 +0530 Subject: [PATCH] test: flag a serial with mismatched in/out valuation --- .../test_incorrect_serial_no_valuation.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/erpnext/stock/report/incorrect_serial_no_valuation/test_incorrect_serial_no_valuation.py b/erpnext/stock/report/incorrect_serial_no_valuation/test_incorrect_serial_no_valuation.py index 9015c06cd1d..81f736928fe 100644 --- a/erpnext/stock/report/incorrect_serial_no_valuation/test_incorrect_serial_no_valuation.py +++ b/erpnext/stock/report/incorrect_serial_no_valuation/test_incorrect_serial_no_valuation.py @@ -3,6 +3,7 @@ import frappe +from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.report.incorrect_serial_no_valuation.incorrect_serial_no_valuation import execute from erpnext.tests.utils import ERPNextTestSuite @@ -53,3 +54,28 @@ class TestIncorrectSerialNoValuation(ERPNextTestSuite): self.assertEqual(len(data), 1) self.assertEqual(data[-1].get("qty"), 0) self.assertEqual(data[-1].get("valuation_rate"), 0) + + def test_mismatched_in_out_valuation_is_flagged(self): + # fresh serial item so only this test's serial movements are considered + item = make_item( + properties={"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "ISV-BAD-.#####"} + ).name + + make_stock_entry(item_code=item, to_warehouse=WAREHOUSE, qty=1, rate=100, posting_date="2026-06-01") + serial_no = frappe.get_all("Serial No", filters={"item_code": item}, pluck="name")[0] + make_stock_entry(item_code=item, from_warehouse=WAREHOUSE, qty=1, posting_date="2026-06-02") + + # corrupt the outgoing valuation so the serial's in (100) and out no longer cancel: + # net qty is 0 but a residual value remains, which the report must flag + frappe.db.set_value( + "Serial and Batch Entry", + {"serial_no": serial_no, "qty": ["<", 0]}, + "incoming_rate", + 60, + update_modified=False, + ) + + data = self.run_report(item_code=item) + + flagged_serials = {row.get("serial_no") for row in data if isinstance(row, dict)} + self.assertIn(serial_no, flagged_serials)