From bdd43274b2fa648202c573ef9b28c4379b2e2a78 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 14 Dec 2021 17:02:42 +0530 Subject: [PATCH] fix: incorrect logic for "Reserved Qty for Production" (#28880) * fix: reservation for production incorrect The query uses case to decide what fields to compute reservation on, this case is outermost case hence the very first Work order's "Skip transfer" is considered for ALL work orders. Solution: move the case inside Sum. Steps to reproduce: 1. Make work order for more than 1 qty (with | without skip transfer) 2. Create manufacture and transfer entries. 3. Keep checking reserved quantities during this process. * test: use default warehouse for testing reservation (cherry picked from commit 80f1a8c645019f0587acd8116117d37e58e680e3) --- erpnext/manufacturing/doctype/work_order/test_work_order.py | 2 +- erpnext/stock/doctype/bin/bin.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 0d7e83927a1..3949fe34852 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -91,7 +91,7 @@ class TestWorkOrder(ERPNextTestCase): def test_reserved_qty_for_partial_completion(self): item = "_Test Item" - warehouse = create_warehouse("Test Warehouse for reserved_qty - _TC") + warehouse = "_Test Warehouse - _TC" bin1_at_start = get_bin(item, warehouse) diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 17c8367a638..27e83caf99b 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -33,10 +33,10 @@ class Bin(Document): in open work orders''' self.reserved_qty_for_production = frappe.db.sql(''' SELECT - CASE WHEN ifnull(skip_transfer, 0) = 0 THEN - SUM(item.required_qty - item.transferred_qty) + SUM(CASE WHEN ifnull(skip_transfer, 0) = 0 THEN + item.required_qty - item.transferred_qty ELSE - SUM(item.required_qty - item.consumed_qty) + item.required_qty - item.consumed_qty END) END FROM `tabWork Order` pro, `tabWork Order Item` item WHERE