diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 24646c7d37a..cf1d19192a1 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -417,7 +417,14 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ args: args, callback: function(r) { if(r.message) { - frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message); + if (r.message.batch_no != null) { + frappe.model.set_value(doc.doctype, doc.name, 'batch_no', r.message.batch_no); + } else if (r.message.msg_print) { + frappe.show_alert({ + message: r.message.msg_print, + indicator:'orange' + }, 5); + } } } }); diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 58c8b9c8dcb..768ea9b6024 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -260,7 +260,9 @@ def set_batch_nos(doc, warehouse_field, throw=False, child_table="items"): warehouse = d.get(warehouse_field, None) if warehouse and qty > 0 and frappe.db.get_value("Item", d.item_code, "has_batch_no"): if not d.batch_no: - d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no) + d.batch_no = get_batch_no(d.item_code, warehouse, qty, throw, d.serial_no).get( + "batch_no", None + ) else: batch_qty = get_batch_qty(batch_no=d.batch_no, warehouse=warehouse) if flt(batch_qty, d.precision("qty")) < flt(qty, d.precision("qty")): @@ -282,6 +284,7 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None): """ batch_no = None + message = None batches = get_batches(item_code, warehouse, qty, throw, serial_no) for batch in batches: @@ -290,15 +293,18 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None): 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)) - ) + message = _( + "Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement" + ).format(frappe.bold(item_code)) if throw: + frappe.msgprint( + _( + "Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement" + ).format(frappe.bold(item_code)) + ) raise UnableToSelectBatchError - return batch_no + return {"batch_no": batch_no, "msg_print": message} def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None): diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 0fec02c7674..4711d039c36 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1262,7 +1262,9 @@ class StockEntry(StockController): and ret.get("has_batch_no") and not args.get("batch_no") ): - args.batch_no = get_batch_no(args["item_code"], args["s_warehouse"], args["qty"]) + args.batch_no = get_batch_no(args["item_code"], args["s_warehouse"], args["qty"]).get( + "batch_no", None + ) if ( self.purpose == "Send to Subcontractor" and self.get("purchase_order") and args.get("item_code") diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index c6243a81dbf..7ba79d0530d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -153,7 +153,7 @@ def update_stock(args, out): ): if out.has_batch_no and not args.get("batch_no"): - out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty) + out.batch_no = get_batch_no(out.item_code, out.warehouse, out.qty).get("batch_no", None) actual_batch_qty = get_batch_qty(out.batch_no, out.warehouse, out.item_code) if actual_batch_qty: out.update(actual_batch_qty)