fix: modify query to fetch valid return qty

This commit is contained in:
ravibharathi656
2025-06-10 18:56:29 +05:30
parent 6529b288c2
commit 161a186bcc

View File

@@ -795,12 +795,14 @@ def get_returned_qty_map(delivery_note):
"""returns a map: {so_detail: returned_qty}""" """returns a map: {so_detail: returned_qty}"""
returned_qty_map = frappe._dict( returned_qty_map = frappe._dict(
frappe.db.sql( frappe.db.sql(
"""select dn_item.dn_detail, abs(dn_item.qty) as qty """select dn_item.dn_detail, sum(abs(dn_item.qty)) as qty
from `tabDelivery Note Item` dn_item, `tabDelivery Note` dn from `tabDelivery Note Item` dn_item, `tabDelivery Note` dn
where dn.name = dn_item.parent where dn.name = dn_item.parent
and dn.docstatus = 1 and dn.docstatus = 1
and dn.is_return = 1 and dn.is_return = 1
and dn.return_against = %s and dn.return_against = %s
and dn_item.qty <= 0
group by dn_item.item_code
""", """,
delivery_note, delivery_note,
) )