diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6ca095869f..3b907daa1b 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1808,14 +1808,44 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } }); -erpnext.show_serial_batch_selector = function(frm, d, callback, on_close, show_dialog) { +erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_dialog) { + let warehouse, receiving_stock, existing_stock; + if (frm.doc.is_return) { + if (["Purchase Receipt", "Purchase Invoice"].includes(frm.doc.doctype)) { + existing_stock = true; + warehouse = d.warehouse; + } else if (["Delivery Note", "Sales Invoice"].includes(frm.doc.doctype)) { + receiving_stock = true; + } + } else { + if (frm.doc.doctype == "Stock Entry") { + if (frm.doc.purpose == "Material Receipt") { + receiving_stock = true; + } else { + existing_stock = true; + warehouse = d.s_warehouse; + } + } else { + existing_stock = true; + warehouse = d.warehouse; + } + } + + if (!warehouse) { + if (receiving_stock) { + warehouse = ["like", ""]; + } else if (existing_stock) { + warehouse = ["!=", ""]; + } + } + frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { new erpnext.SerialNoBatchSelector({ frm: frm, item: d, warehouse_details: { type: "Warehouse", - name: d.warehouse + name: warehouse }, callback: callback, on_close: on_close diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index 41a59d0af5..61a693933f 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -389,12 +389,14 @@ erpnext.SerialNoBatchSelector = Class.extend({ let serial_no_filters = { item_code: me.item_code, + batch_no: this.doc.batch_no || null, delivery_document_no: "" } if (me.warehouse_details.name) { serial_no_filters['warehouse'] = me.warehouse_details.name; } + return [ {fieldtype: 'Section Break', label: __('Serial Numbers')}, {