From 20a80fee454a88d7618b1d9dd3a44972ab2a303d Mon Sep 17 00:00:00 2001 From: yimesgen Date: Mon, 23 Jul 2018 12:06:50 +0300 Subject: [PATCH] Update batch.py (#14905) * Update batch.py Performance improvements for pos stock availability checks on a particular warehouse due to the slowing down effects of the where clauses combined by the "and". * Update batch.py --- erpnext/stock/doctype/batch/batch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 9d13657d8a..8be489de50 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -251,8 +251,8 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False): def get_batches(item_code, warehouse, qty=1, throw=False): batches = frappe.db.sql( - 'select batch_id, sum(actual_qty) as qty from `tabBatch` join `tabStock Ledger Entry` ' - 'on `tabBatch`.batch_id = `tabStock Ledger Entry`.batch_no ' + 'select batch_id, sum(actual_qty) as qty from `tabBatch` join `tabStock Ledger Entry` ignore index (item_code, warehouse) ' + 'on `(tabBatch`.batch_id = `tabStock Ledger Entry`.batch_no )' 'where `tabStock Ledger Entry`.item_code = %s and `tabStock Ledger Entry`.warehouse = %s ' 'and (`tabBatch`.expiry_date >= CURDATE() or `tabBatch`.expiry_date IS NULL)' 'group by batch_id '