diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index b2619634b9d..d1d5d77f285 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -496,18 +496,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)) {