feat: don't reserve qty on sales return
This commit is contained in:
parent
17f8080168
commit
3c553b0938
@ -94,10 +94,13 @@ def get_balance_qty_from_sle(item_code, warehouse):
|
||||
|
||||
|
||||
def get_reserved_qty(item_code, warehouse):
|
||||
dont_reserve_on_return = frappe.get_cached_value(
|
||||
"Selling Settings", "Selling Settings", "dont_reserve_sales_order_qty_on_sales_return"
|
||||
)
|
||||
reserved_qty = frappe.db.sql(
|
||||
"""
|
||||
f"""
|
||||
select
|
||||
sum(dnpi_qty * ((so_item_qty - so_item_delivered_qty) / so_item_qty))
|
||||
sum(dnpi_qty * ((so_item_qty - so_item_delivered_qty - if(dont_reserve_qty_on_return, so_item_returned_qty, 0)) / so_item_qty))
|
||||
from
|
||||
(
|
||||
(select
|
||||
@ -112,6 +115,12 @@ 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,
|
||||
{dont_reserve_on_return} as dont_reserve_qty_on_return,
|
||||
parent, name
|
||||
from
|
||||
(
|
||||
@ -125,7 +134,9 @@ 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,
|
||||
{dont_reserve_on_return}, 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)
|
||||
|
Loading…
Reference in New Issue
Block a user