Skip to content

Commit

Permalink
chore: patch to set reserved stock in Bin
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Nov 4, 2023
1 parent 1024223 commit 1f88b1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions erpnext/patches/v15_0/set_reserved_stock_in_bin.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 1f88b1e

Please sign in to comment.