From ba5f571b0d243a8d44f1d189ec42db187ca91d9d Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Mon, 29 Jun 2020 17:35:27 +0530 Subject: [PATCH] fix: take parent cost center for child if no cost center at child (#22496) --- erpnext/hr/doctype/expense_claim/expense_claim.js | 8 +++++--- erpnext/hr/doctype/expense_claim/expense_claim.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index fa63ec2834..8f8dafdd7f 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -300,6 +300,11 @@ frappe.ui.form.on("Expense Claim", { cost_center: function(frm) { frm.events.set_child_cost_center(frm); }, + + validate: function(frm) { + frm.events.set_child_cost_center(frm); + }, + set_child_cost_center: function(frm){ (frm.doc.expenses || []).forEach(function(d) { if (!d.cost_center){ @@ -349,9 +354,6 @@ frappe.ui.form.on("Expense Claim", { }); frappe.ui.form.on("Expense Claim Detail", { - expenses_add: function(frm, cdt, cdn) { - frm.events.set_child_cost_center(frm); - }, amount: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; frappe.model.set_value(cdt, cdn, 'sanctioned_amount', child.amount); diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index ea469b82c9..5563c245f4 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -129,7 +129,7 @@ class ExpenseClaim(AccountsController): "debit": data.sanctioned_amount, "debit_in_account_currency": data.sanctioned_amount, "against": self.employee, - "cost_center": data.cost_center + "cost_center": data.cost_center or self.cost_center }, item=data) )