feat: order only the items ticked in the supplier selection dialog

Every row is ticked when the dialog opens, so the common case of ordering
everything is unchanged, and a buyer who wants a partial order unticks what
should wait. Creating with nothing ticked is rejected.

(cherry picked from commit 07445b3675)
This commit is contained in:
Mihir Kandoi
2026-08-01 09:00:12 +05:30
committed by Mergify
parent 810b9ae28f
commit d6ee5436b8
2 changed files with 8 additions and 2 deletions

View File

@@ -207,6 +207,9 @@ def get_item_default_suppliers(source_name: str, filtered_children: str | list |
def make_purchase_orders_by_supplier(source_name: str, item_suppliers: str | list) -> list[str]:
"""Create one draft Purchase Order per supplier for the given Material Request items."""
item_suppliers = frappe.parse_json(item_suppliers)
if not item_suppliers:
frappe.throw(_("Select at least one Item"))
pending_items = {
d["material_request_item"]: frappe._dict(d) for d in get_item_default_suppliers(source_name)
}

View File

@@ -445,7 +445,7 @@ frappe.ui.form.on("Material Request", {
},
select_suppliers_for_items: function (frm, items) {
const rows = items.map((item) => Object.assign({}, item, { qty: item.pending_qty }));
const rows = items.map((item) => Object.assign({}, item, { qty: item.pending_qty, __checked: 1 }));
const dialog = new frappe.ui.Dialog({
title: __("Select Supplier for Items"),
@@ -519,7 +519,10 @@ frappe.ui.form.on("Material Request", {
],
primary_action_label: __("Create"),
primary_action: function (values) {
const item_suppliers = values.items || [];
const item_suppliers = (values.items || []).filter((row) => row.__checked);
if (!item_suppliers.length) {
frappe.throw(__("Select at least one Item"));
}
const missing_supplier = item_suppliers.find((row) => !row.supplier);
if (missing_supplier) {