fix(stock): map only undelivered bundles from a pick list to the delivery note

the bundle row created from a pick list was sized from the full picked component qty, so a second delivery note after a partial delivery delivered the whole pick again and the sales order ended over-delivered. count picked minus delivered per component location when mapping, as plain rows already do, and skip bundles with nothing left.
This commit is contained in:
Sudharsanan11
2026-10-29 16:04:14 +05:30
parent 995a3c95f7
commit e3c6082498
2 changed files with 9 additions and 4 deletions
+5 -1
View File
@@ -360,8 +360,12 @@ def add_product_bundles_to_target(
)
)
pending_qty = pick_list._compute_picked_qty_for_bundle(so_row, bundle_items, pending_only=True)
if not pending_qty:
continue
target_bundle_item = map_child_doc(sales_order_item, target_doc, item_mapper)
target_bundle_item.qty = pick_list._compute_picked_qty_for_bundle(so_row, bundle_items)
target_bundle_item.qty = pending_qty
target_bundle_item.against_pick_list = pick_list.name
update_child_item(sales_order_item, target_bundle_item, target_doc)
+4 -3
View File
@@ -1080,8 +1080,8 @@ class PickList(TransactionBase):
}
return product_bundle_qty_map
def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items) -> int:
"""Compute how many full bundles can be created from picked items."""
def _compute_picked_qty_for_bundle(self, bundle_row, bundle_items, pending_only=False) -> int:
"""Compute how many full bundles can be created from picked (or picked but undelivered) items."""
precision = frappe.get_precision("Stock Ledger Entry", "qty_after_transaction")
possible_bundles = {}
for item in self.locations:
@@ -1089,8 +1089,9 @@ class PickList(TransactionBase):
continue
if qty_in_bundle := bundle_items.get(item.item_code):
qty = flt(item.picked_qty) - (flt(item.delivered_qty) if pending_only else 0)
possible_bundles.setdefault(item.product_bundle_item, 0)
possible_bundles[item.product_bundle_item] += item.picked_qty / qty_in_bundle
possible_bundles[item.product_bundle_item] += qty / qty_in_bundle
return int(flt(min(possible_bundles.values()), precision or 6)) if possible_bundles else 0