mirror of
https://github.com/frappe/erpnext.git
synced 2026-07-21 20:00:38 +00:00
fix(stock): backfill transferred qty for existing pick lists
Pick Lists transferred before this feature have transferred_qty = 0 and
their Stock Entry rows carry no pick_list_item link, so the new
is_fully_transferred check would never fire and, with the old
duplicate-entry guard removed, they could be transferred again. Set
transferred_qty = picked_qty for non-Delivery submitted pick lists that
already have a linked Stock Entry so they stay completed and locked.
(cherry picked from commit 903d78cc43)
This commit is contained in:
@@ -440,4 +440,5 @@ erpnext.patches.v16_0.set_posting_datetime_for_sabb_and_drop_indexes
|
||||
execute:frappe.db.set_single_value("Accounts Settings", "pcv_job_timeout", 3600)
|
||||
erpnext.patches.v15_0.backfill_sla_link_filters_on_custom_field
|
||||
erpnext.patches.v15_0.backfill_sla_link_filters_on_docfield
|
||||
erpnext.patches.v16_0.crm_settings_handle_allowed_users_for_frappe_crm
|
||||
erpnext.patches.v16_0.crm_settings_handle_allowed_users_for_frappe_crm
|
||||
erpnext.patches.v16_0.backfill_pick_list_transferred_qty
|
||||
|
||||
58
erpnext/patches/v16_0/backfill_pick_list_transferred_qty.py
Normal file
58
erpnext/patches/v16_0/backfill_pick_list_transferred_qty.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import frappe
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.utils import flt
|
||||
|
||||
|
||||
def execute():
|
||||
StockEntry = frappe.qb.DocType("Stock Entry")
|
||||
StockEntryDetail = frappe.qb.DocType("Stock Entry Detail")
|
||||
|
||||
pick_lists = (
|
||||
frappe.qb.from_(StockEntry)
|
||||
.select(StockEntry.pick_list)
|
||||
.distinct()
|
||||
.where((StockEntry.pick_list.isnotnull()) & (StockEntry.docstatus == 1))
|
||||
).run(pluck=True)
|
||||
|
||||
if not pick_lists:
|
||||
return
|
||||
|
||||
rows = (
|
||||
frappe.qb.from_(StockEntryDetail)
|
||||
.join(StockEntry)
|
||||
.on(StockEntryDetail.parent == StockEntry.name)
|
||||
.select(
|
||||
StockEntry.pick_list,
|
||||
StockEntryDetail.item_code,
|
||||
StockEntryDetail.s_warehouse,
|
||||
Sum(StockEntryDetail.transfer_qty).as_("qty"),
|
||||
)
|
||||
.where((StockEntry.pick_list.isin(pick_lists)) & (StockEntry.docstatus == 1))
|
||||
.groupby(StockEntry.pick_list, StockEntryDetail.item_code, StockEntryDetail.s_warehouse)
|
||||
).run(as_dict=True)
|
||||
|
||||
transferred = {(r.pick_list, r.item_code, r.s_warehouse): flt(r.qty) for r in rows}
|
||||
|
||||
items = frappe.get_all(
|
||||
"Pick List Item",
|
||||
filters={"parent": ("in", pick_lists), "picked_qty": (">", 0)},
|
||||
fields=["name", "parent", "item_code", "warehouse", "picked_qty"],
|
||||
order_by="idx",
|
||||
)
|
||||
|
||||
updates = {}
|
||||
for row in items:
|
||||
key = (row.parent, row.item_code, row.warehouse)
|
||||
available = transferred.get(key, 0)
|
||||
if available <= 0:
|
||||
continue
|
||||
qty = min(flt(row.picked_qty), available)
|
||||
transferred[key] = available - qty
|
||||
updates[row.name] = {"transferred_qty": qty}
|
||||
|
||||
if not updates:
|
||||
return
|
||||
|
||||
frappe.db.auto_commit_on_many_writes = True
|
||||
frappe.db.bulk_update("Pick List Item", updates)
|
||||
frappe.db.auto_commit_on_many_writes = False
|
||||
Reference in New Issue
Block a user