fix: Tax amount not considered in Expense Claim Journal Entry
- add a helper function `get_outstanding_amount_for_claim` for uniformity in usages
This commit is contained in:
@@ -25,7 +25,10 @@ from erpnext.accounts.utils import (
|
||||
get_stock_and_account_balance,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
|
||||
from erpnext.hr.doctype.expense_claim.expense_claim import (
|
||||
get_outstanding_amount_for_claim,
|
||||
update_reimbursed_amount,
|
||||
)
|
||||
|
||||
|
||||
class StockAccountInvalidTransaction(frappe.ValidationError):
|
||||
@@ -935,15 +938,12 @@ class JournalEntry(AccountsController):
|
||||
def validate_expense_claim(self):
|
||||
for d in self.accounts:
|
||||
if d.reference_type == "Expense Claim":
|
||||
sanctioned_amount, reimbursed_amount = frappe.db.get_value(
|
||||
"Expense Claim", d.reference_name, ("total_sanctioned_amount", "total_amount_reimbursed")
|
||||
)
|
||||
pending_amount = flt(sanctioned_amount) - flt(reimbursed_amount)
|
||||
if d.debit > pending_amount:
|
||||
outstanding_amt = get_outstanding_amount_for_claim(d.reference_name)
|
||||
if d.debit > outstanding_amt:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Row No {0}: Amount cannot be greater than Pending Amount against Expense Claim {1}. Pending Amount is {2}"
|
||||
).format(d.idx, d.reference_name, pending_amount)
|
||||
"Row No {0}: Amount cannot be greater than the Outstanding Amount against Expense Claim {1}. Outstanding Amount is {2}"
|
||||
).format(d.idx, d.reference_name, outstanding_amt)
|
||||
)
|
||||
|
||||
def validate_credit_debit_note(self):
|
||||
|
||||
@@ -30,7 +30,10 @@ from erpnext.controllers.accounts_controller import (
|
||||
get_supplier_block_status,
|
||||
validate_taxes_and_charges,
|
||||
)
|
||||
from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
|
||||
from erpnext.hr.doctype.expense_claim.expense_claim import (
|
||||
get_outstanding_amount_for_claim,
|
||||
update_reimbursed_amount,
|
||||
)
|
||||
from erpnext.setup.utils import get_exchange_rate
|
||||
|
||||
|
||||
@@ -1649,12 +1652,7 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
|
||||
outstanding_amount = ref_doc.get("outstanding_amount")
|
||||
bill_no = ref_doc.get("bill_no")
|
||||
elif reference_doctype == "Expense Claim":
|
||||
outstanding_amount = (
|
||||
flt(ref_doc.get("total_sanctioned_amount"))
|
||||
+ flt(ref_doc.get("total_taxes_and_charges"))
|
||||
- flt(ref_doc.get("total_amount_reimbursed"))
|
||||
- flt(ref_doc.get("total_advance_amount"))
|
||||
)
|
||||
outstanding_amount = get_outstanding_amount_for_claim(ref_doc)
|
||||
elif reference_doctype == "Employee Advance":
|
||||
outstanding_amount = flt(ref_doc.advance_amount) - flt(ref_doc.paid_amount)
|
||||
if party_account_currency != ref_doc.currency:
|
||||
|
||||
@@ -339,6 +339,30 @@ def update_reimbursed_amount(doc, amount):
|
||||
frappe.db.set_value("Expense Claim", doc.name, "status", doc.status)
|
||||
|
||||
|
||||
def get_outstanding_amount_for_claim(claim):
|
||||
if isinstance(claim, str):
|
||||
claim = frappe.db.get_value(
|
||||
"Expense Claim",
|
||||
claim,
|
||||
(
|
||||
"total_sanctioned_amount",
|
||||
"total_taxes_and_charges",
|
||||
"total_amount_reimbursed",
|
||||
"total_advance_amount",
|
||||
),
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
outstanding_amt = (
|
||||
flt(claim.total_sanctioned_amount)
|
||||
+ flt(claim.total_taxes_and_charges)
|
||||
- flt(claim.total_amount_reimbursed)
|
||||
- flt(claim.total_advance_amount)
|
||||
)
|
||||
|
||||
return outstanding_amt
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_bank_entry(dt, dn):
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
|
||||
@@ -348,11 +372,7 @@ def make_bank_entry(dt, dn):
|
||||
if not default_bank_cash_account:
|
||||
default_bank_cash_account = get_default_bank_cash_account(expense_claim.company, "Cash")
|
||||
|
||||
payable_amount = (
|
||||
flt(expense_claim.total_sanctioned_amount)
|
||||
- flt(expense_claim.total_amount_reimbursed)
|
||||
- flt(expense_claim.total_advance_amount)
|
||||
)
|
||||
payable_amount = get_outstanding_amount_for_claim(expense_claim)
|
||||
|
||||
je = frappe.new_doc("Journal Entry")
|
||||
je.voucher_type = "Bank Entry"
|
||||
|
||||
Reference in New Issue
Block a user