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;
|
||||||
}
|
}
|
||||||
return frappe.call({
|
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: {
|
args: {
|
||||||
"expense_claim_type": d.expense_type,
|
"expense_claim_type": d.expense_type,
|
||||||
"company": doc.company
|
"company": doc.company
|
||||||
@ -25,6 +25,7 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
|
|||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
d.default_account = r.message.account;
|
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
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe, erpnext
|
||||||
from frappe import _
|
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 frappe.model.document import Document
|
||||||
from erpnext.hr.utils import set_employee_name
|
from erpnext.hr.utils import set_employee_name
|
||||||
from erpnext.accounts.party import get_party_account
|
from erpnext.accounts.party import get_party_account
|
||||||
@ -192,7 +192,8 @@ class ExpenseClaim(AccountsController):
|
|||||||
def validate_account_details(self):
|
def validate_account_details(self):
|
||||||
for data in self.expenses:
|
for data in self.expenses:
|
||||||
if not data.cost_center:
|
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 self.is_paid:
|
||||||
if not self.mode_of_payment:
|
if not self.mode_of_payment:
|
||||||
@ -308,13 +309,23 @@ def make_bank_entry(dt, dn):
|
|||||||
|
|
||||||
return je.as_dict()
|
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()
|
@frappe.whitelist()
|
||||||
def get_expense_claim_account(expense_claim_type, company):
|
def get_expense_claim_account(expense_claim_type, company):
|
||||||
account = frappe.db.get_value("Expense Claim Account",
|
account = frappe.db.get_value("Expense Claim Account",
|
||||||
{"parent": expense_claim_type, "company": company}, "default_account")
|
{"parent": expense_claim_type, "company": company}, "default_account")
|
||||||
if not account:
|
if not account:
|
||||||
frappe.throw(_("Please set default account in Expense Claim Type {0}")
|
frappe.throw(_("Set the default account for the {0} {1}")
|
||||||
.format(expense_claim_type))
|
.format(frappe.bold("Expense Claim Type"), get_link_to_form("Expense Claim Type", expense_claim_type)))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"account": account
|
"account": account
|
||||||
|
Loading…
x
Reference in New Issue
Block a user