From de54f3019f6f6f6015be4d05dfb9021482a5aafa Mon Sep 17 00:00:00 2001 From: tundebabzy Date: Tue, 25 Jul 2017 06:35:07 +0100 Subject: [PATCH] use api to get default cost center for chosen company (#10067) --- .../doctype/journal_entry/journal_entry.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 577c77f958..9047a4edcc 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -43,8 +43,26 @@ frappe.ui.form.on("Journal Entry", { $.each(frm.doc.accounts || [], function(i, row) { erpnext.journal_entry.set_exchange_rate(frm, row.doctype, row.name); }) + }, + + company: function(frm) { + frappe.call({ + method: "frappe.client.get_value", + args: { + doctype: "Company", + filters: {"name": frm.doc.company}, + fieldname: "cost_center" + }, + callback: function(r){ + if(r.message){ + $.each(frm.doc.accounts || [], function(i, jvd) { + frappe.model.set_value(jvd.doctype, jvd.name, "cost_center", r.message.cost_center); + }); + } + } + }); } -}) +}); erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ onload: function() {