From 3345ef379445d3fa4ac4baf77df6fb3bf0b5d15a Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Fri, 1 Mar 2024 14:52:09 +0100 Subject: [PATCH] fix: better handle down payment selection on checking checkbox --- .../accounts/doctype/purchase_invoice/purchase_invoice.js | 8 +++----- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 09a1c104162..2c9b77f3da0 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -713,12 +713,10 @@ frappe.ui.form.on("Purchase Invoice", { }) frm.refresh_field("items"); - frappe.db.get_list("Item", {filters: {is_down_payment_item: 1}}) + frappe.db.get_list("Item", {filters: {is_down_payment_item: 1}, order_by: "down_payment_percentage DESC"}) .then(r => { - if (r.length == 1) { - frm.doc.items.forEach(line => { - frappe.model.set_value(line.doctype, line.name, "item_code", r[0].name) - }) + if (!r.exc && r.length) { + frappe.model.set_value(frm.doc.items[0].doctype, frm.doc.items[0].name, "item_code", r[0].name) } }) } diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index ecf403a42aa..19b7995523b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -1035,12 +1035,10 @@ frappe.ui.form.on('Sales Invoice', { }) frm.refresh_field("items"); - frappe.db.get_list("Item", {filters: {is_down_payment_item: 1}}) + frappe.db.get_list("Item", {filters: {is_down_payment_item: 1}, order_by: "down_payment_percentage DESC"}) .then(r => { - if (r.length == 1) { - frm.doc.items.forEach(line => { - frappe.model.set_value(line.doctype, line.name, "item_code", r[0].name) - }) + if (!r.exc && r.length) { + frappe.model.set_value(frm.doc.items[0].doctype, frm.doc.items[0].name, "item_code", r[0].name) } }) } -- GitLab