From 2bf9fcb81718f882f33893d53b1bf6019f3a90fd Mon Sep 17 00:00:00 2001 From: Raghav Ruia Date: Wed, 24 Jun 2026 16:06:30 +0530 Subject: [PATCH 1/2] feat: confirmation dialog when enabling negative stock on Item Co-Authored-By: Claude Opus 4.8 --- erpnext/stock/doctype/item/item.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index ed6d4efe43d..d4cd4b61f6a 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -54,6 +54,28 @@ frappe.ui.form.on("Item", { } }, + allow_negative_stock(frm) { + if (!frm.doc.allow_negative_stock) { + return; + } + + let msg = __( + "Using negative stock disables FIFO/Moving average valuation when inventory is negative." + ); + msg += " "; + msg += __("This is considered dangerous from accounting point of view."); + msg += "
"; + msg += __("Do you still want to enable negative inventory?"); + + frappe.confirm( + msg, + () => {}, + () => { + frm.set_value("allow_negative_stock", 0); + } + ); + }, + setup: function (frm) { frm.add_fetch("attribute", "numeric_values", "numeric_values"); frm.add_fetch("attribute", "from_range", "from_range"); From 69d5d2bbc169c779681f7dcbe2c4d80a3a821667 Mon Sep 17 00:00:00 2001 From: Raghav Ruia Date: Fri, 26 Jun 2026 09:38:23 +0530 Subject: [PATCH 2/2] refactor: extract negative stock confirmation into shared util Deduplicate the identical confirmation dialog used by Item and Stock Settings into erpnext.utils.confirm_negative_stock, and collapse the message into a single translatable string. Co-Authored-By: Claude Opus 4.8 --- erpnext/public/js/utils.js | 12 +++++++++++ erpnext/stock/doctype/item/item.js | 20 +------------------ .../doctype/stock_settings/stock_settings.js | 20 +------------------ 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 51637316446..acaf7fb056e 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -562,6 +562,18 @@ $.extend(erpnext.utils, { }, }); +erpnext.utils.confirm_negative_stock = function (frm) { + if (!frm.doc.allow_negative_stock) return; + + frappe.confirm( + __( + "Using negative stock disables FIFO/Moving average valuation when inventory is negative. This is considered dangerous from accounting point of view.
Do you still want to enable negative inventory?" + ), + () => {}, + () => frm.set_value("allow_negative_stock", 0) + ); +}; + erpnext.utils.select_alternate_items = function (opts) { const frm = opts.frm; const warehouse_field = opts.warehouse_field || "warehouse"; diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index d4cd4b61f6a..3bc7499aaee 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -55,25 +55,7 @@ frappe.ui.form.on("Item", { }, allow_negative_stock(frm) { - if (!frm.doc.allow_negative_stock) { - return; - } - - let msg = __( - "Using negative stock disables FIFO/Moving average valuation when inventory is negative." - ); - msg += " "; - msg += __("This is considered dangerous from accounting point of view."); - msg += "
"; - msg += __("Do you still want to enable negative inventory?"); - - frappe.confirm( - msg, - () => {}, - () => { - frm.set_value("allow_negative_stock", 0); - } - ); + erpnext.utils.confirm_negative_stock(frm); }, setup: function (frm) { diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js index 3d70c199d05..db0c7bb337c 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.js +++ b/erpnext/stock/doctype/stock_settings/stock_settings.js @@ -96,25 +96,7 @@ frappe.ui.form.on("Stock Settings", { }, allow_negative_stock: function (frm) { - if (!frm.doc.allow_negative_stock) { - return; - } - - let msg = __( - "Using negative stock disables FIFO/Moving average valuation when inventory is negative." - ); - msg += " "; - msg += __("This is considered dangerous from accounting point of view."); - msg += "
"; - msg += __("Do you still want to enable negative inventory?"); - - frappe.confirm( - msg, - () => {}, - () => { - frm.set_value("allow_negative_stock", 0); - } - ); + erpnext.utils.confirm_negative_stock(frm); }, auto_insert_price_list_rate_if_missing(frm) { if (!frm.doc.auto_insert_price_list_rate_if_missing) return;