Skip to content

Commit

Permalink
fix: incorrect limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Dec 18, 2023
1 parent 20a764a commit 7fa56ea
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def get_available_item_locations_for_serialized_item(
.select(sn.name, sn.warehouse)
.where((sn.item_code == item_code) & (sn.company == company))
.orderby(sn.purchase_date)
.limit(cint(required_qty + total_picked_qty))
.limit(get_limit_for_query(required_qty + total_picked_qty))
)

if from_warehouses:
Expand Down Expand Up @@ -647,7 +647,7 @@ def get_available_item_locations_for_batched_item(
.groupby(sle.warehouse, sle.batch_no, sle.item_code)
.having(Sum(sle.actual_qty) > 0)
.orderby(IfNull(batch.expiry_date, "2200-01-01"), batch.creation, sle.batch_no, sle.warehouse)
.limit(cint(required_qty + total_picked_qty))
.limit(get_limit_for_query(required_qty + total_picked_qty))
)

if from_warehouses:
Expand All @@ -656,6 +656,14 @@ def get_available_item_locations_for_batched_item(
return query.run(as_dict=True)


def get_limit_for_query(required_qty):
required_qty = cint(required_qty)
if required_qty == 0:
return 1

return required_qty


def get_available_item_locations_for_serial_and_batched_item(
item_code, from_warehouses, required_qty, company, total_picked_qty=0
):
Expand All @@ -680,7 +688,7 @@ def get_available_item_locations_for_serial_and_batched_item(
(conditions) & (sn.batch_no == location.batch_no) & (sn.warehouse == location.warehouse)
)
.orderby(sn.purchase_date)
.limit(cint(location.qty + total_picked_qty))
.limit(get_limit_for_query(location.qty + total_picked_qty))
).run(as_dict=True)

serial_nos = [sn.name for sn in serial_nos]
Expand All @@ -699,7 +707,7 @@ def get_available_item_locations_for_other_item(
.select(bin.warehouse, bin.actual_qty.as_("qty"))
.where((bin.item_code == item_code) & (bin.actual_qty > 0))
.orderby(bin.creation)
.limit(cint(required_qty + total_picked_qty))
.limit(get_limit_for_query(required_qty + total_picked_qty))
)

if from_warehouses:
Expand Down

0 comments on commit 7fa56ea

Please sign in to comment.