fix(stock): subtract stock qty of same-document rows from batch availability (#58669)

* fix(stock): subtract stock qty of same-document rows from batch availability

filter_batches subtracted a row's transaction-UOM qty from batch quantities that
are in the stock UOM, so a row in an alternate UOM freed less of the batch than
it consumes and the auto-pick could assign a batch that cannot cover the new
row.

* test(stock): cover batch availability with alternate UOM rows
This commit is contained in:
Mihir Kandoi
2026-09-02 11:42:37 +05:30
committed by GitHub
parent 9261c9b47f
commit 199cae9496
2 changed files with 14 additions and 1 deletions

View File

@@ -381,7 +381,7 @@ def get_batch_no_covering_qty(kwargs, doc, qty):
def filter_batches(batches, doc):
for row in doc.get("items"):
if row.get("batch_no") in batches:
batches[row.get("batch_no")] -= row.get("qty")
batches[row.get("batch_no")] -= flt(row.get("stock_qty"))
if batches[row.get("batch_no")] <= 0:
del batches[row.get("batch_no")]

View File

@@ -547,3 +547,16 @@ class TestGetItemDetail(ERPNextTestSuite):
self.assertEqual(
get_serial_nos_from_bundle(dn.items[0].serial_and_batch_bundle), sorted(serial_nos)
)
def test_same_document_rows_reduce_batch_by_stock_qty(self):
item_code, batches = self.make_batched_item_with_stock(
[10], uoms=[{"uom": "Box", "conversion_factor": 5}]
)
box_row = [{"batch_no": batches[0], "uom": "Box", "qty": 1, "stock_qty": 5}]
with self.change_settings(
"Stock Settings",
{"pick_serial_and_batch_based_on": "FIFO", "auto_create_serial_and_batch_bundle_for_outward": 1},
):
self.assertEqual(self.get_picked_batch_no(item_code, 5, items=box_row), batches[0])
self.assertIsNone(self.get_picked_batch_no(item_code, 6, items=box_row))