fix: open the Purchase Order when the supplier selection creates only one

Naming a single order in a message and leaving the buyer to click it is a step
for nothing. The form opens directly when there is one order; the message stays
for the case it was meant for, several orders at once.

(cherry picked from commit 3856eaa35e)
This commit is contained in:
Mihir Kandoi
2026-08-01 09:02:05 +05:30
committed by Mergify
parent 6096e761b0
commit e71cef02b3
2 changed files with 12 additions and 6 deletions

View File

@@ -260,11 +260,12 @@ def make_purchase_orders_by_supplier(source_name: str, item_suppliers: str | lis
indicator="orange",
)
frappe.msgprint(
_("{0} created").format(
comma_and([get_link_to_form("Purchase Order", name) for name in purchase_orders])
if len(purchase_orders) > 1:
frappe.msgprint(
_("{0} created").format(
comma_and([get_link_to_form("Purchase Order", name) for name in purchase_orders])
)
)
)
return purchase_orders

View File

@@ -550,8 +550,13 @@ frappe.ui.form.on("Material Request", {
args: { source_name: frm.doc.name, item_suppliers: item_suppliers },
freeze: true,
callback: function (r) {
if (!r.exc) {
dialog.hide();
if (r.exc) return;
dialog.hide();
const purchase_orders = r.message || [];
if (purchase_orders.length === 1) {
frappe.set_route("Form", "Purchase Order", purchase_orders[0]);
}
},
});