From 3642f987c73d139bbb2148ac3f2c189aa513f74e Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 27 Jul 2016 11:42:38 +0530 Subject: [PATCH] [fix] report filter fix --- erpnext/stock/report/stock_balance/stock_balance.py | 8 +++++--- erpnext/stock/report/stock_ledger/stock_ledger.py | 12 +++++++----- .../stock_projected_qty/stock_projected_qty.py | 10 ++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py index 2777d3d216..d5d6f9dbe4 100644 --- a/erpnext/stock/report/stock_balance/stock_balance.py +++ b/erpnext/stock/report/stock_balance/stock_balance.py @@ -71,9 +71,11 @@ def get_conditions(filters): conditions += " and item_code = '%s'" % frappe.db.escape(filters.get("item_code"), percent=False) if filters.get("warehouse"): - lft, rgt = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"]) - conditions += " and exists (select name from `tabWarehouse` wh \ - where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(lft, rgt) + warehouse_details = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1) + if warehouse_details: + conditions += " and exists (select name from `tabWarehouse` wh \ + where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(warehouse_details.lft, + warehouse_details.rgt) return conditions diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index b2e46701da..69fb4900e5 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -99,8 +99,10 @@ def get_opening_balance(filters, columns): return row def get_warehouse_condition(warehouse): - lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"]) - - return " exists (select name from `tabWarehouse` wh \ - where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(lft, rgt) - \ No newline at end of file + warehouse_details = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"], as_dict=1) + if warehouse_details: + return " exists (select name from `tabWarehouse` wh \ + where wh.lft >= %s and wh.rgt <= %s and sle.warehouse = wh.name)"%(warehouse_details.lft, + warehouse_details.rgt) + + return '' diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py index f90fb49045..21287b9d9e 100644 --- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py +++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py @@ -63,10 +63,12 @@ def get_bin_list(filters): conditions.append("item_code = '%s' "%filters.item_code) if filters.warehouse: - lft, rgt = frappe.db.get_value("Warehouse", filters.warehouse, ["lft", "rgt"]) - - conditions.append(" exists (select name from `tabWarehouse` wh \ - where wh.lft >= %s and wh.rgt <= %s and bin.warehouse = wh.name)"%(lft, rgt)) + warehouse_details = frappe.db.get_value("Warehouse", filters.warehouse, ["lft", "rgt"], as_dict=1) + + if warehouse_details: + conditions.append(" exists (select name from `tabWarehouse` wh \ + where wh.lft >= %s and wh.rgt <= %s and bin.warehouse = wh.name)"%(warehouse_details.lft, + warehouse_details.rgt)) bin_list = frappe.db.sql("""select item_code, warehouse, actual_qty, planned_qty, indented_qty, ordered_qty, reserved_qty, reserved_qty_for_production, projected_qty