[fix] Check for stock_qty, else use qty (#10937)

This commit is contained in:
Prateeksha Singh 2017-09-27 17:12:28 +05:30 committed by Nabin Hait
parent da8de2f0c7
commit 283922daa2

View File

@ -103,14 +103,15 @@ def split_batch(batch_no, item_code, warehouse, qty, new_batch_id = None):
def set_batch_nos(doc, warehouse_field, throw = False): def set_batch_nos(doc, warehouse_field, throw = False):
'''Automatically select `batch_no` for outgoing items in item table''' '''Automatically select `batch_no` for outgoing items in item table'''
for d in doc.items: for d in doc.items:
qty = d.get('stock_qty') or d.get('qty') or 0
has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no') has_batch_no = frappe.db.get_value('Item', d.item_code, 'has_batch_no')
warehouse = d.get(warehouse_field, None) warehouse = d.get(warehouse_field, None)
if has_batch_no and warehouse and d.stock_qty > 0: if has_batch_no and warehouse and qty > 0:
if not d.batch_no: if not d.batch_no:
d.batch_no = get_batch_no(d.item_code, warehouse, d.stock_qty, throw) d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw)
else: else:
batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse) batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse)
if flt(batch_qty) < flt(d.stock_qty): if flt(batch_qty) < flt(qty):
frappe.throw(_("Row #{0}: The batch {1} has only {2} qty. Please select another batch which has {3} qty available or split the row into multiple rows, to deliver/issue from multiple batches").format(d.idx, d.batch_no, batch_qty, d.qty)) frappe.throw(_("Row #{0}: The batch {1} has only {2} qty. Please select another batch which has {3} qty available or split the row into multiple rows, to deliver/issue from multiple batches").format(d.idx, d.batch_no, batch_qty, d.qty))
def get_batch_no(item_code, warehouse, qty, throw=False): def get_batch_no(item_code, warehouse, qty, throw=False):