refactor: rewrite get_picked_items_qty query in QB

This commit is contained in:
s-aga-r 2023-01-21 11:28:23 +05:30
parent 4cbd63edbf
commit 29bf787313

View File

@ -347,28 +347,23 @@ class PickList(Document):
def get_picked_items_qty(items) -> List[Dict]: def get_picked_items_qty(items) -> List[Dict]:
return frappe.db.sql( pi_item = frappe.qb.DocType("Pick List Item")
f""" return (
SELECT frappe.qb.from_(pi_item)
sales_order_item, .select(
item_code, pi_item.sales_order_item,
sales_order, pi_item.item_code,
SUM(stock_qty) AS stock_qty, pi_item.sales_order,
SUM(picked_qty) AS picked_qty Sum(pi_item.stock_qty).as_("stock_qty"),
FROM Sum(pi_item.picked_qty).as_("picked_qty"),
`tabPick List Item` )
WHERE .where((pi_item.docstatus == 1) & (pi_item.sales_order_item.isin(items)))
sales_order_item IN ( .groupby(
{", ".join(frappe.db.escape(d) for d in items)} pi_item.sales_order_item,
) pi_item.sales_order,
AND docstatus = 1 )
GROUP BY .for_update()
sales_order_item, ).run(as_dict=True)
sales_order
FOR UPDATE
""",
as_dict=1,
)
def validate_item_locations(pick_list): def validate_item_locations(pick_list):