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
This commit is contained in:
Nabin Hait
2026-07-17 14:11:26 +05:30
parent 4177101ac0
commit 77540403ab

View File

@@ -9,11 +9,14 @@ frappe.ui.form.on("Sales Order", {
frappe.db.get_single_value("Selling Settings", "enable_proforma_invoice").then((enabled) => { frappe.db.get_single_value("Selling Settings", "enable_proforma_invoice").then((enabled) => {
if (!enabled) return; if (!enabled) return;
frm.add_custom_button( // Defer so the button lands after the standard Create options, not before them.
__("Proforma Invoice"), setTimeout(() => {
() => erpnext.proforma.open_dialog(frm), frm.add_custom_button(
__("Create") __("Proforma Invoice"),
); () => erpnext.proforma.open_dialog(frm),
__("Create")
);
}, 0);
erpnext.proforma.render_list(frm); erpnext.proforma.render_list(frm);
}); });
}, },
@@ -94,7 +97,12 @@ Object.assign(erpnext.proforma, {
fieldname: "items", fieldname: "items",
fieldtype: "Table", fieldtype: "Table",
cannot_add_rows: true, 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: [ fields: [
{ {
fieldname: "item_code", fieldname: "item_code",