fix: better validation message for the expense claim and set default cost center in the expenses table (#21454)
This commit is contained in:
parent
558f6aa4cb
commit
daf37e7570
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user