From 3f9b8fe37ee8a9c4ba0d67c77b0e6446727bae11 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 2 Jul 2026 17:03:32 +0530 Subject: [PATCH] test: reconcile negative-stock warehouses in reset_item_valuation_rate --- erpnext/manufacturing/doctype/bom/test_bom.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 7797d819e39..2af6dbecb1a 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -881,8 +881,13 @@ def reset_item_valuation_rate(item_code, warehouse_list=None, qty=None, rate=Non warehouse_list = [warehouse_list] if not warehouse_list: + # Reconcile every warehouse the item has a non-zero balance in -- including + # negative balances left by other tests. `get_valuation_rate` averages + # Sum(stock_value)/Sum(actual_qty) across all bins, so a leftover negative + # balance in one warehouse can cancel the reset qty elsewhere and make the + # average collapse to 0, which is a source of flaky BOM-cost failures. warehouse_list = frappe.get_all( - "Bin", filters={"item_code": item_code, "actual_qty": [">", 0]}, pluck="warehouse" + "Bin", filters={"item_code": item_code, "actual_qty": ["!=", 0]}, pluck="warehouse" ) if not warehouse_list: