Skip to content

Commit

Permalink
fix: incorrect limit (#38818)
Browse files Browse the repository at this point in the history
(cherry picked from commit e18dc5c)

# Conflicts:
#	erpnext/stock/doctype/pick_list/pick_list.py
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Dec 18, 2023
1 parent b5f3013 commit 702ded9
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
from frappe.model.mapper import map_child_doc
from frappe.query_builder import Case
from frappe.query_builder.custom import GROUP_CONCAT
<<<<<<< HEAD
from frappe.query_builder.functions import Coalesce, Locate, Replace, Sum
from frappe.utils import cint, floor, flt
=======
from frappe.query_builder.functions import Coalesce, IfNull, Locate, Replace, Sum
from frappe.utils import ceil, cint, floor, flt, today
>>>>>>> e18dc5cea3 (fix: incorrect limit (#38818))
from frappe.utils.nestedset import get_descendants_of

from erpnext.selling.doctype.sales_order.sales_order import (
Expand Down Expand Up @@ -728,8 +733,13 @@ def get_available_item_locations_for_serialized_item(
frappe.qb.from_(sn)
.select(sn.name, sn.warehouse)
.where((sn.item_code == item_code) & (sn.company == company))
<<<<<<< HEAD
.orderby(sn.creation)
.limit(cint(required_qty + total_picked_qty))
=======
.orderby(sn.purchase_date)
.limit(ceil(required_qty + total_picked_qty))
>>>>>>> e18dc5cea3 (fix: incorrect limit (#38818))
)

if from_warehouses:
Expand Down Expand Up @@ -789,6 +799,13 @@ def get_available_item_locations_for_batched_item(
"qty": required_qty + total_picked_qty,
}
)
<<<<<<< HEAD
=======
.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(ceil(required_qty + total_picked_qty))
>>>>>>> e18dc5cea3 (fix: incorrect limit (#38818))
)

warehouse_wise_batches = frappe._dict()
Expand All @@ -814,6 +831,7 @@ def get_available_item_locations_for_batched_item(
}
).make_serial_and_batch_bundle()

<<<<<<< HEAD
locations.append(
{
"qty": qty,
Expand All @@ -822,6 +840,30 @@ def get_available_item_locations_for_batched_item(
"serial_and_batch_bundle": bundle_doc.name,
}
)
=======
if locations:
sn = frappe.qb.DocType("Serial No")
conditions = (sn.item_code == item_code) & (sn.company == company)

for location in locations:
location.qty = (
required_qty if location.qty > required_qty else location.qty
) # if extra qty in batch

serial_nos = (
frappe.qb.from_(sn)
.select(sn.name)
.where(
(conditions) & (sn.batch_no == location.batch_no) & (sn.warehouse == location.warehouse)
)
.orderby(sn.purchase_date)
.limit(ceil(location.qty + total_picked_qty))
).run(as_dict=True)

serial_nos = [sn.name for sn in serial_nos]
location.serial_no = serial_nos
location.qty = len(serial_nos)
>>>>>>> e18dc5cea3 (fix: incorrect limit (#38818))

return locations

Expand All @@ -835,7 +877,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(ceil(required_qty + total_picked_qty))
)

if from_warehouses:
Expand Down

0 comments on commit 702ded9

Please sign in to comment.