chore: patch to set reserved stock in Bin

This commit is contained in:
s-aga-r 2023-11-01 20:48:09 +05:30
parent 10242235bc
commit 1f88b1ef84
2 changed files with 25 additions and 0 deletions

View File

@ -347,5 +347,6 @@ execute:frappe.db.set_single_value("Payment Reconciliation", "invoice_limit", 50
execute:frappe.db.set_single_value("Payment Reconciliation", "payment_limit", 50)
erpnext.patches.v15_0.rename_daily_depreciation_to_depreciation_amount_based_on_num_days_in_month
erpnext.patches.v15_0.rename_depreciation_amount_based_on_num_days_in_month_to_daily_prorata_based
erpnext.patches.v15_0.set_reserved_stock_in_bin
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger

View File

@ -0,0 +1,24 @@
import frappe
from frappe.query_builder.functions import Sum
def execute():
sre = frappe.qb.DocType("Stock Reservation Entry")
query = (
frappe.qb.from_(sre)
.select(
sre.item_code,
sre.warehouse,
Sum(sre.reserved_qty - sre.delivered_qty).as_("reserved_stock"),
)
.where((sre.docstatus == 1) & (sre.status.notin(["Delivered", "Cancelled"])))
.groupby(sre.item_code, sre.warehouse)
)
for d in query.run(as_dict=True):
frappe.db.set_value(
"Bin",
{"item_code": d.item_code, "warehouse": d.warehouse},
"reserved_stock",
d.reserved_stock,
)