fix: incorrect POS Reserved Qty in Stock Projected Qty Report (#35437)

* fix: incorrect `POS Reserved Qty` in `Stock Projected Qty` Report

(cherry picked from commit 027de41600)

# Conflicts:
#	erpnext/accounts/doctype/pos_invoice/pos_invoice.py

* chore: `conflicts`

---------

Co-authored-by: Sagar Sharma <sagarsharma.s312@gmail.com>
This commit is contained in:
mergify[bot]
2023-05-29 09:24:20 +05:30
committed by GitHub
parent 4f5ee6876d
commit 139a193f1d

View File

@@ -4,6 +4,7 @@
import frappe import frappe
from frappe import _ from frappe import _
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import cint, flt, get_link_to_form, getdate, nowdate from frappe.utils import cint, flt, get_link_to_form, getdate, nowdate
from six import iteritems from six import iteritems
@@ -675,18 +676,22 @@ def get_bin_qty(item_code, warehouse):
def get_pos_reserved_qty(item_code, warehouse): def get_pos_reserved_qty(item_code, warehouse):
reserved_qty = frappe.db.sql( p_inv = frappe.qb.DocType("POS Invoice")
"""select sum(p_item.qty) as qty p_item = frappe.qb.DocType("POS Invoice Item")
from `tabPOS Invoice` p, `tabPOS Invoice Item` p_item
where p.name = p_item.parent reserved_qty = (
and ifnull(p.consolidated_invoice, '') = '' frappe.qb.from_(p_inv)
and p_item.docstatus = 1 .from_(p_item)
and p_item.item_code = %s .select(Sum(p_item.qty).as_("qty"))
and p_item.warehouse = %s .where(
""", (p_inv.name == p_item.parent)
(item_code, warehouse), & (IfNull(p_inv.consolidated_invoice, "") == "")
as_dict=1, & (p_inv.is_return == 0)
) & (p_item.docstatus == 1)
& (p_item.item_code == item_code)
& (p_item.warehouse == warehouse)
)
).run(as_dict=True)
return reserved_qty[0].qty or 0 if reserved_qty else 0 return reserved_qty[0].qty or 0 if reserved_qty else 0