From 89959976bdc6110630d523b92c7c9321b4aace05 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 9 Feb 2022 11:38:52 +0530 Subject: [PATCH] fix: patch existing bins --- erpnext/patches.txt | 1 + .../v13_0/update_reserved_qty_closed_wo.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 erpnext/patches/v13_0/update_reserved_qty_closed_wo.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index feafecbc04..d300340671 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -350,3 +350,4 @@ erpnext.patches.v14_0.migrate_cost_center_allocations erpnext.patches.v13_0.convert_to_website_item_in_item_card_group_template erpnext.patches.v13_0.shopping_cart_to_ecommerce erpnext.patches.v13_0.update_disbursement_account +erpnext.patches.v13_0.update_reserved_qty_closed_wo diff --git a/erpnext/patches/v13_0/update_reserved_qty_closed_wo.py b/erpnext/patches/v13_0/update_reserved_qty_closed_wo.py new file mode 100644 index 0000000000..00926b0924 --- /dev/null +++ b/erpnext/patches/v13_0/update_reserved_qty_closed_wo.py @@ -0,0 +1,28 @@ +import frappe + +from erpnext.stock.utils import get_bin + + +def execute(): + + wo = frappe.qb.DocType("Work Order") + wo_item = frappe.qb.DocType("Work Order Item") + + incorrect_item_wh = ( + frappe.qb + .from_(wo) + .join(wo_item).on(wo.name == wo_item.parent) + .select(wo_item.item_code, wo.source_warehouse).distinct() + .where( + (wo.status == "Closed") + & (wo.docstatus == 1) + & (wo.source_warehouse.notnull()) + ) + ).run() + + for item_code, warehouse in incorrect_item_wh: + if not (item_code and warehouse): + continue + + bin = get_bin(item_code, warehouse) + bin.update_reserved_qty_for_production()