[fix] Get open SO in production planning tool

This commit is contained in:
Nabin Hait 2015-08-03 16:39:20 +05:30
parent ba9dbb1b09
commit 541927d58a

View File

@ -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)