From 0e62b21c92b865f2316baf49ac21a5920b90b195 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 30 May 2024 18:06:29 +0530 Subject: [PATCH] fix: batch selection issue (#41692) --- erpnext/controllers/queries.py | 2 ++ erpnext/public/js/controllers/transaction.js | 3 +++ .../stock/doctype/stock_entry/stock_entry.js | 4 +++- .../doctype/stock_settings/stock_settings.js | 18 +++++++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 26cab3c36f..adc17fb3ea 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -499,6 +499,7 @@ def get_batches_from_stock_ledger_entries(searchfields, txt, filters, start=0, p & (stock_ledger_entry.batch_no.isnotnull()) ) .groupby(stock_ledger_entry.batch_no, stock_ledger_entry.warehouse) + .having(Sum(stock_ledger_entry.actual_qty) > 0) .offset(start) .limit(page_len) ) @@ -549,6 +550,7 @@ def get_batches_from_serial_and_batch_bundle(searchfields, txt, filters, start=0 & (stock_ledger_entry.serial_and_batch_bundle.isnotnull()) ) .groupby(bundle.batch_no, bundle.warehouse) + .having(Sum(bundle.qty) > 0) .offset(start) .limit(page_len) ) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index d608da61c8..7265f28677 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2395,6 +2395,9 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe if (doc.is_return) { filters["is_return"] = 1; + if (["Sales Invoice", "Delivery Note"].includes(doc.doctype)) { + filters["is_inward"] = 1; + } } if (item.warehouse) filters["warehouse"] = item.warehouse; diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 0d47a25ee6..f71dbf005b 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -96,7 +96,9 @@ frappe.ui.form.on('Stock Entry', { // or a pre-existing batch if (frm.doc.purpose != "Material Receipt") { filters["warehouse"] = item.s_warehouse || item.t_warehouse; - } else { + } + + if (!item.s_warehouse && item.t_warehouse) { filters["is_inward"] = 1; } diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js index b4b4d4e211..aa5f8141aa 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.js +++ b/erpnext/stock/doctype/stock_settings/stock_settings.js @@ -14,7 +14,23 @@ frappe.ui.form.on('Stock Settings', { frm.set_query("default_warehouse", filters); frm.set_query("sample_retention_warehouse", filters); }, - allow_negative_stock: function(frm) { + + use_serial_batch_fields(frm) { + if (frm.doc.use_serial_batch_fields && !frm.doc.disable_serial_no_and_batch_selector) { + frm.set_value("disable_serial_no_and_batch_selector", 1); + } + }, + + disable_serial_no_and_batch_selector(frm) { + if (!frm.doc.disable_serial_no_and_batch_selector && frm.doc.use_serial_batch_fields) { + frm.set_value("disable_serial_no_and_batch_selector", 1); + frappe.msgprint( + __("Serial No and Batch Selector cannot be use when Use Serial / Batch Fields is enabled.") + ); + } + }, + + allow_negative_stock: function (frm) { if (!frm.doc.allow_negative_stock) { return; } -- GitLab