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.

(cherry picked from commit f0bb70539d)
This commit is contained in:
Mihir Kandoi
2026-08-01 09:16:13 +05:30
committed by Mergify
parent 380ee3b013
commit 93331a1cf0

View File

@@ -518,7 +518,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"));
@@ -552,6 +552,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 },