From 7146c0385cdf13322c80ff8daf112dfc4856d295 Mon Sep 17 00:00:00 2001 From: SowmyaArunachalam Date: Tue, 27 Jan 2026 15:37:14 +0530 Subject: [PATCH] fix: handle parent level project change (cherry picked from commit 543b6e51c08f281bd733cd0d0ceb44a480f9cf35) --- erpnext/public/js/utils/sales_common.js | 34 ++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index 1adbe402744..c9b5ed7e6f2 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -489,18 +489,28 @@ erpnext.sales_common = { } project(doc, cdt, cdn) { - const item = frappe.get_doc(cdt, cdn); - if (item.project) { - $.each(this.frm.doc["items"] || [], function (i, other_item) { - if (!other_item.project) { - frappe.model.set_value( - other_item.doctype, - other_item.name, - "project", - item.project - ); - } - }); + if (!cdt || !cdn) { + if (this.frm.doc.project) { + $.each(this.frm.doc["items"] || [], function (i, item) { + if (!item.project) { + frappe.model.set_value(item.doctype, item.name, "project", doc.project); + } + }); + } + } else { + const item = frappe.get_doc(cdt, cdn); + if (item.project) { + $.each(this.frm.doc["items"] || [], function (i, other_item) { + if (!other_item.project) { + frappe.model.set_value( + other_item.doctype, + other_item.name, + "project", + item.project + ); + } + }); + } } let me = this; if (["Delivery Note", "Sales Invoice", "Sales Order"].includes(this.frm.doc.doctype)) {