From 77540403ab152e8d2ee78abe8921e7b102ccbea7 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 17 Jul 2026 14:11:26 +0530 Subject: [PATCH] feat(selling): prefill remaining proforma qty/amount and reorder Create button - Pre-fill each line with the remaining (ordered minus already proformed) qty and amount, so the default no longer trips the excess warning - Place the Proforma Invoice action after the standard Create options --- erpnext/public/js/sales_order_proforma.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/erpnext/public/js/sales_order_proforma.js b/erpnext/public/js/sales_order_proforma.js index 9d1c9c3b294..fabbb67df69 100644 --- a/erpnext/public/js/sales_order_proforma.js +++ b/erpnext/public/js/sales_order_proforma.js @@ -9,11 +9,14 @@ frappe.ui.form.on("Sales Order", { frappe.db.get_single_value("Selling Settings", "enable_proforma_invoice").then((enabled) => { if (!enabled) return; - frm.add_custom_button( - __("Proforma Invoice"), - () => erpnext.proforma.open_dialog(frm), - __("Create") - ); + // Defer so the button lands after the standard Create options, not before them. + setTimeout(() => { + frm.add_custom_button( + __("Proforma Invoice"), + () => erpnext.proforma.open_dialog(frm), + __("Create") + ); + }, 0); erpnext.proforma.render_list(frm); }); }, @@ -94,7 +97,12 @@ Object.assign(erpnext.proforma, { fieldname: "items", fieldtype: "Table", cannot_add_rows: true, - data: so_items.map((row) => ({ ...row })), + // Pre-fill the remaining (ordered minus already-proformed) for each basis. + data: so_items.map((row) => ({ + ...row, + qty: Math.max(0, flt(row.qty) - flt(row.proformed_qty)), + amount: Math.max(0, flt(row.amount) - flt(row.proformed_amount)), + })), fields: [ { fieldname: "item_code",