From 541927d58a8a7b1ab3065e65a0581be8b240ec7f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 3 Aug 2015 16:39:20 +0530 Subject: [PATCH] [fix] Get open SO in production planning tool --- .../production_planning_tool.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) 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 c4cebb80bb..e302cc782b 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 @@ class ProductionPlanningTool(Document): """ 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)