diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 88f3865434..fb2310396b 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -17,7 +17,7 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({ return; } return frappe.call({ - method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account", + method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center", args: { "expense_claim_type": d.expense_type, "company": doc.company @@ -25,6 +25,7 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({ callback: function(r) { if (r.message) { d.default_account = r.message.account; + d.cost_center = r.message.cost_center; } } }); diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index fe8afdf873..ad9d86b66e 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -2,9 +2,9 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -import frappe +import frappe, erpnext from frappe import _ -from frappe.utils import get_fullname, flt, cstr +from frappe.utils import get_fullname, flt, cstr, get_link_to_form from frappe.model.document import Document from erpnext.hr.utils import set_employee_name from erpnext.accounts.party import get_party_account @@ -192,7 +192,8 @@ class ExpenseClaim(AccountsController): def validate_account_details(self): for data in self.expenses: if not data.cost_center: - frappe.throw(_("Cost center is required to book an expense claim")) + frappe.throw(_("Row {0}: {1} is required in the expenses table to book an expense claim.") + .format(data.idx, frappe.bold("Cost Center"))) if self.is_paid: if not self.mode_of_payment: @@ -308,13 +309,23 @@ def make_bank_entry(dt, dn): return je.as_dict() +@frappe.whitelist() +def get_expense_claim_account_and_cost_center(expense_claim_type, company): + data = get_expense_claim_account(expense_claim_type, company) + cost_center = erpnext.get_default_cost_center(company) + + return { + "account": data.get("account"), + "cost_center": cost_center + } + @frappe.whitelist() def get_expense_claim_account(expense_claim_type, company): account = frappe.db.get_value("Expense Claim Account", {"parent": expense_claim_type, "company": company}, "default_account") if not account: - frappe.throw(_("Please set default account in Expense Claim Type {0}") - .format(expense_claim_type)) + frappe.throw(_("Set the default account for the {0} {1}") + .format(frappe.bold("Expense Claim Type"), get_link_to_form("Expense Claim Type", expense_claim_type))) return { "account": account