PP tool: get items from SO based on item filter
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 1e75319..a59e0e9 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -106,14 +106,21 @@
msgprint(_("Please enter sales order in the above table"))
return []
+ item_condition = ""
+ if self.fg_item:
+ item_condition = ' and so_item.item_code = "' + self.fg_item + '"'
+
items = frappe.db.sql("""select distinct parent, item_code, warehouse,
(qty - ifnull(delivered_qty, 0)) as pending_qty
from `tabSales Order Item` so_item
where parent in (%s) and docstatus = 1 and ifnull(qty, 0) > ifnull(delivered_qty, 0)
and exists (select * from `tabItem` item where item.name=so_item.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
- or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
- (", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
+ or ifnull(item.is_sub_contracted_item, 'No') = 'Yes')) %s""" % \
+ (", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1)
+
+ if self.fg_item:
+ item_condition = ' and pi.item_code = "' + self.fg_item + '"'
packed_items = frappe.db.sql("""select distinct pi.parent, pi.item_code, pi.warehouse as reserved_warhouse,
(((so_item.qty - ifnull(so_item.delivered_qty, 0)) * pi.qty) / so_item.qty)
@@ -124,8 +131,8 @@
and so_item.parent in (%s) and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0)
and exists (select * from `tabItem` item where item.name=pi.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
- or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
- (", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
+ or ifnull(item.is_sub_contracted_item, 'No') = 'Yes')) %s""" % \
+ (", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1)
return items + packed_items