mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user