Merge pull request #3783 from nabinhait/fix2
[fix] Get open SO in production planning tool
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 c4cebb8..e302cc7 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -44,31 +44,35 @@
""" Pull sales orders which are pending to deliver based on criteria selected"""
so_filter = item_filter = ""
if self.from_date:
- so_filter += ' and so.transaction_date >= "' + self.from_date + '"'
+ so_filter += " and so.transaction_date >= %(from_date)s"
if self.to_date:
- so_filter += ' and so.transaction_date <= "' + self.to_date + '"'
+ so_filter += " and so.transaction_date <= %(to_date)s"
if self.customer:
- so_filter += ' and so.customer = "' + self.customer + '"'
+ so_filter += " and so.customer = %(customer)s"
if self.fg_item:
- item_filter += ' and item.name = "' + self.fg_item + '"'
+ item_filter += " and item.name = %(item)s"
open_so = frappe.db.sql("""
select distinct so.name, so.transaction_date, so.customer, so.base_grand_total
from `tabSales Order` so, `tabSales Order Item` so_item
where so_item.parent = so.name
and so.docstatus = 1 and so.status != "Stopped"
- and so.company = %s
- and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0) %s
+ and so.company = %(company)s
+ and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0) {0}
and (exists (select name from `tabItem` item where item.name=so_item.item_code
- and (item.is_pro_applicable = 1
- or item.is_sub_contracted_item = 1 %s)
+ and (item.is_pro_applicable = 1 or item.is_sub_contracted_item = 1 {1}))
or exists (select name from `tabPacked Item` pi
where pi.parent = so.name and pi.parent_item = so_item.item_code
and exists (select name from `tabItem` item where item.name=pi.item_code
- and (item.is_pro_applicable = 1
- or item.is_sub_contracted_item = 1) %s)))
- """ % ('%s', so_filter, item_filter, item_filter), self.company, as_dict=1)
+ and (item.is_pro_applicable = 1 or item.is_sub_contracted_item = 1) {2})))
+ """.format(so_filter, item_filter, item_filter), {
+ "from_date": self.from_date,
+ "to_date": self.to_date,
+ "customer": self.customer,
+ "item": self.fg_item,
+ "company": self.company
+ }, as_dict=1)
self.add_so_in_table(open_so)