From f0bb70539db2c484c543ccb614a0a45b11b7dfe6 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 1 Aug 2026 09:16:13 +0530 Subject: [PATCH] fix: warn about existing draft orders before the supplier selection creates more Creating through the dialog calls the endpoint directly instead of going through open_mapped_doc, so the draft link guard that every other Create action runs never fired, and a repeated dialog quietly produced a second set of draft orders for the same quantity. --- erpnext/stock/doctype/material_request/material_request.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index 9efbe1ff22b..1218df0a58f 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -512,7 +512,7 @@ frappe.ui.form.on("Material Request", { }, ], primary_action_label: __("Create"), - primary_action: function (values) { + primary_action: async function (values) { const item_suppliers = (values.items || []).filter((row) => row.__checked); if (!item_suppliers.length) { frappe.throw(__("Select at least one Item")); @@ -546,6 +546,10 @@ frappe.ui.form.on("Material Request", { ); } + if (!(await erpnext.utils.confirm_if_drafts_exist(frm.doc, "Purchase Order"))) { + return; + } + frappe.call({ method: "erpnext.stock.doctype.material_request.mapper.make_purchase_orders_by_supplier", args: { source_name: frm.doc.name, item_suppliers: item_suppliers },