From 695e2bcfbcb27d0502bfd0620d5a4d3268175e14 Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Sat, 14 May 2022 11:06:24 -0400 Subject: [PATCH] fix: don't reserve qty on sales return. --- erpnext/stock/stock_balance.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index e05d1c3a29..cf5acbdd55 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -97,7 +97,7 @@ def get_reserved_qty(item_code, warehouse): reserved_qty = frappe.db.sql( """ select - sum(dnpi_qty * ((so_item_qty - so_item_delivered_qty) / so_item_qty)) + sum(dnpi_qty * ((so_item_qty - so_item_delivered_qty - so_item_returned_qty) / so_item_qty)) from ( (select @@ -112,6 +112,11 @@ def get_reserved_qty(item_code, warehouse): where name = dnpi.parent_detail_docname and delivered_by_supplier = 0 ) as so_item_delivered_qty, + ( + select returned_qty from `tabSales Order Item` + where name = dnpi.parent_detail_docname + and delivered_by_supplier = 0 + ) as so_item_returned_qty, parent, name from ( @@ -125,7 +130,8 @@ def get_reserved_qty(item_code, warehouse): ) dnpi) union (select stock_qty as dnpi_qty, qty as so_item_qty, - delivered_qty as so_item_delivered_qty, parent, name + delivered_qty as so_item_delivered_qty, + returned_qty as so_item_returned_qty, parent, name from `tabSales Order Item` so_item where item_code = %s and warehouse = %s and (so_item.delivered_by_supplier is null or so_item.delivered_by_supplier = 0)