Pick batch autmatically only if batch found

This commit is contained in:
Nabin Hait 2017-04-26 14:29:33 +05:30
parent db8f41ba55
commit 96c247c834

View File

@ -101,16 +101,18 @@ def set_batch_nos(doc, warehouse_field, throw = False):
def get_batch_no(item_code, warehouse, qty, 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''' '''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 batch_no = None
for b in batches:
if b.qty >= qty: batches = get_batch_qty(item_code = item_code, warehouse = warehouse)
batch_no = b.batch_no if batches:
# found! batches = sorted(batches, lambda a, b: 1 if a.qty > b.qty else -1)
break
for b in batches:
if b.qty >= qty:
batch_no = b.batch_no
# found!
break
if not batch_no: 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))) frappe.msgprint(_('Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement').format(frappe.bold(item_code)))