From 41659a875b23a8dc65c6cead2a9e091a6a4f4453 Mon Sep 17 00:00:00 2001 From: Navin-S-R Date: Fri, 12 Dec 2025 14:25:08 +0530 Subject: [PATCH] refactor: standardize cost_center updation across transactions (cherry picked from commit c28f6f1856daf22d295525e2311f2dc966fb4b73) # Conflicts: # erpnext/accounts/doctype/sales_invoice/sales_invoice.js --- .../doctype/purchase_invoice/purchase_invoice.js | 11 ----------- .../accounts/doctype/sales_invoice/sales_invoice.js | 4 ---- erpnext/public/js/controllers/transaction.js | 8 ++------ erpnext/stock/doctype/delivery_note/delivery_note.js | 4 ---- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 2e7e0314aba..52f68180267 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -575,17 +575,6 @@ cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function }; }; -cur_frm.cscript.cost_center = function (doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if (d.cost_center) { - var cl = doc.items || []; - for (var i = 0; i < cl.length; i++) { - if (!cl[i].cost_center) cl[i].cost_center = d.cost_center; - } - } - refresh_field("items"); -}; - cur_frm.fields_dict["items"].grid.get_field("project").get_query = function (doc, cdt, cdn) { return { filters: [["Project", "status", "not in", "Completed, Cancelled"]], diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index abb5d76b9d8..9711c4637bc 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -648,10 +648,6 @@ cur_frm.cscript.expense_account = function (doc, cdt, cdn) { erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "expense_account"); }; -cur_frm.cscript.cost_center = function (doc, cdt, cdn) { - erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "cost_center"); -}; - cur_frm.set_query("debit_to", function (doc) { return { filters: { diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index f61de798390..1b23042769e 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1093,12 +1093,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.frm.refresh_field("payment_schedule"); } - cost_center(doc) { - this.frm.doc.items.forEach((item) => { - item.cost_center = doc.cost_center; - }); - - this.frm.refresh_field("items"); + cost_center(doc, cdt, cdn) { + erpnext.utils.copy_value_in_all_rows(doc, cdt, cdn, "items", "cost_center"); } due_date(doc, cdt, cdn) { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index b9c98bbb8ba..cdb219180ad 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -130,10 +130,6 @@ frappe.ui.form.on("Delivery Note Item", { var d = locals[dt][dn]; frm.update_in_all_rows("items", "expense_account", d.expense_account); }, - cost_center: function (frm, dt, dn) { - var d = locals[dt][dn]; - frm.update_in_all_rows("items", "cost_center", d.cost_center); - }, }); erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends (