From 96c247c83420b5a594f9d65831ccbbcf2bdee1cf Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 26 Apr 2017 14:29:33 +0530 Subject: [PATCH] Pick batch autmatically only if batch found --- erpnext/stock/doctype/batch/batch.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 8ef8e915ee..5749afb8e7 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -101,16 +101,18 @@ def set_batch_nos(doc, warehouse_field, throw = False): def get_batch_no(item_code, warehouse, qty, throw=False): '''get the smallest batch with for the given item_code, warehouse and qty''' - batches = sorted( - get_batch_qty(item_code = item_code, warehouse = warehouse), - lambda a, b: 1 if a.qty > b.qty else -1) - + batch_no = None - for b in batches: - if b.qty >= qty: - batch_no = b.batch_no - # found! - break + + batches = get_batch_qty(item_code = item_code, warehouse = warehouse) + if batches: + batches = sorted(batches, lambda a, b: 1 if a.qty > b.qty else -1) + + for b in batches: + if b.qty >= qty: + batch_no = b.batch_no + # found! + break if not batch_no: frappe.msgprint(_('Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement').format(frappe.bold(item_code)))