Skip to content

Commit

Permalink
fix: incorrect qty picked in the pick list (#41378)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5ed1b6b)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed May 8, 2024
1 parent bba738f commit 0db2223
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ def filter_locations_by_picked_materials(locations, picked_item_details) -> list

picked_qty = picked_item_details.get(key, {}).get("picked_qty", 0)
if not picked_qty:
filterd_locations.append(row)
continue
if picked_qty > row.qty:
row.qty = 0
Expand Down
118 changes: 118 additions & 0 deletions erpnext/stock/doctype/pick_list/test_pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,3 +1013,121 @@ def test_pick_list_validation_for_multiple_batches_and_sales_order(self):
pl.submit()
self.assertEqual(pl.locations[0].qty, 4.0)
self.assertTrue(hasattr(pl, "locations"))

def test_pick_list_for_multiple_sales_order_with_multiple_batches(self):
warehouse = "_Test Warehouse - _TC"
item = make_item(
"Test Batch Pick List Item For Multiple Batches and Sales Order",
properties={
"is_stock_item": 1,
"has_batch_no": 1,
"batch_number_series": "SN-SOO-BT-SPLIMBATCH-.####",
"create_new_batch": 1,
},
).name

make_stock_entry(item=item, to_warehouse=warehouse, qty=100)
make_stock_entry(item=item, to_warehouse=warehouse, qty=100)

so = make_sales_order(item_code=item, qty=10, rate=100)

pl1 = create_pick_list(so.name)
pl1.save()
self.assertEqual(pl1.locations[0].qty, 10)

so = make_sales_order(item_code=item, qty=110, rate=100)

pl = create_pick_list(so.name)
pl.save()
self.assertEqual(pl.locations[0].qty, 90.0)
self.assertEqual(pl.locations[1].qty, 20.0)
self.assertTrue(hasattr(pl, "locations"))

pl1.submit()

pl.reload()
pl.submit()
self.assertEqual(pl.locations[0].qty, 90.0)
self.assertEqual(pl.locations[1].qty, 20.0)
self.assertTrue(hasattr(pl, "locations"))

def test_pick_list_for_multiple_sales_order_with_multiple_serial_nos(self):
warehouse = "_Test Warehouse - _TC"
item = make_item(
"Test Serial No Pick List Item For Multiple Batches and Sales Order",
properties={
"is_stock_item": 1,
"has_serial_no": 1,
"serial_no_series": "SNNN-SOO-BT-SPLIMBATCH-.####",
},
).name

make_stock_entry(item=item, to_warehouse=warehouse, qty=100)
make_stock_entry(item=item, to_warehouse=warehouse, qty=100)

so = make_sales_order(item_code=item, qty=10, rate=100)

pl1 = create_pick_list(so.name)
pl1.save()
self.assertEqual(pl1.locations[0].qty, 10)

serial_nos = pl1.locations[0].serial_no.split("\n")
self.assertEqual(len(serial_nos), 10)

so = make_sales_order(item_code=item, qty=110, rate=100)

pl = create_pick_list(so.name)
pl.save()
self.assertEqual(pl.locations[0].qty, 110.0)
self.assertTrue(hasattr(pl, "locations"))

new_serial_nos = pl.locations[0].serial_no.split("\n")
self.assertEqual(len(new_serial_nos), 110)

for sn in serial_nos:
self.assertFalse(sn in new_serial_nos)

pl1.submit()

pl.reload()
pl.submit()
self.assertEqual(pl.locations[0].qty, 110.0)
self.assertTrue(hasattr(pl, "locations"))

def test_pick_list_for_multiple_sales_orders_for_non_serialized_item(self):
warehouse = "_Test Warehouse - _TC"
item = make_item(
"Test Non Serialized Pick List Item For Multiple Batches and Sales Order",
properties={
"is_stock_item": 1,
},
).name

make_stock_entry(item=item, to_warehouse=warehouse, qty=100)
make_stock_entry(item=item, to_warehouse=warehouse, qty=100)

so = make_sales_order(item_code=item, qty=10, rate=100)

pl1 = create_pick_list(so.name)
pl1.save()
self.assertEqual(pl1.locations[0].qty, 10)

so = make_sales_order(item_code=item, qty=110, rate=100)

pl = create_pick_list(so.name)
pl.save()
self.assertEqual(pl.locations[0].qty, 110.0)
self.assertTrue(hasattr(pl, "locations"))

pl1.submit()

pl.reload()
pl.submit()
self.assertEqual(pl.locations[0].qty, 110.0)
self.assertTrue(hasattr(pl, "locations"))

so = make_sales_order(item_code=item, qty=110, rate=100)
pl = create_pick_list(so.name)
pl.save()

self.assertEqual(pl.locations[0].qty, 80.0)

0 comments on commit 0db2223

Please sign in to comment.