Skip to content

Commit

Permalink
Merge pull request #1802 from krantheman/fix-outstanding-amount
Browse files Browse the repository at this point in the history
fix(Expense Claim): update of Outstanding Amount on Payment Entry submission
  • Loading branch information
ruchamahabal authored May 23, 2024
2 parents 3922770 + 7387348 commit 78f68f3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
15 changes: 11 additions & 4 deletions hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,17 @@ def update_payment_for_expense_claim(doc, method=None):
for d in doc.get(payment_table):
if d.get(doctype_field) == "Expense Claim" and d.reference_name:
expense_claim = frappe.get_doc("Expense Claim", d.reference_name)
if doc.docstatus == 2:
update_reimbursed_amount(expense_claim)
else:
update_reimbursed_amount(expense_claim)
update_reimbursed_amount(expense_claim)

if doc.doctype == "Payment Entry":
update_outstanding_amount_in_payment_entry(expense_claim, d.name)


def update_outstanding_amount_in_payment_entry(expense_claim: dict, pe_reference: str):
"""updates outstanding amount back in Payment Entry reference"""
# TODO: refactor convoluted code after erpnext payment entry becomes extensible
outstanding_amount = get_outstanding_amount_for_claim(expense_claim)
frappe.db.set_value("Payment Entry Reference", pe_reference, "outstanding_amount", outstanding_amount)


def validate_expense_claim_in_jv(doc, method=None):
Expand Down
52 changes: 24 additions & 28 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from erpnext.setup.doctype.employee.test_employee import make_employee

from hrms.hr.doctype.expense_claim.expense_claim import (
get_outstanding_amount_for_claim,
make_bank_entry,
make_expense_claim_for_delivery_trip,
)
Expand Down Expand Up @@ -392,28 +393,34 @@ def test_multiple_payment_entries_against_expense(self):
expense_claim.submit()

# Payment entry 1: paying 500
make_payment_entry(expense_claim, 500)
outstanding_amount, total_amount_reimbursed = get_outstanding_and_total_reimbursed_amounts(
expense_claim
)
pe1 = make_payment_entry(expense_claim, 500)
pe1.reload()
self.assertEqual(pe1.references[0].outstanding_amount, 5000)

expense_claim.reload()
outstanding_amount = get_outstanding_amount_for_claim(expense_claim)
self.assertEqual(outstanding_amount, 5000)
self.assertEqual(total_amount_reimbursed, 500)
self.assertEqual(expense_claim.total_amount_reimbursed, 500)

# Payment entry 1: paying 2000
make_payment_entry(expense_claim, 2000)
outstanding_amount, total_amount_reimbursed = get_outstanding_and_total_reimbursed_amounts(
expense_claim
)
# Payment entry 2: paying 2000
pe2 = make_payment_entry(expense_claim, 2000)
pe2.reload()
self.assertEqual(pe2.references[0].outstanding_amount, 3000)

expense_claim.reload()
outstanding_amount = get_outstanding_amount_for_claim(expense_claim)
self.assertEqual(outstanding_amount, 3000)
self.assertEqual(total_amount_reimbursed, 2500)
self.assertEqual(expense_claim.total_amount_reimbursed, 2500)

# Payment entry 1: paying 3000
make_payment_entry(expense_claim, 3000)
outstanding_amount, total_amount_reimbursed = get_outstanding_and_total_reimbursed_amounts(
expense_claim
)
# Payment entry 3: paying 3000
pe3 = make_payment_entry(expense_claim, 3000)
pe3.reload()
self.assertEqual(pe3.references[0].outstanding_amount, 0)

expense_claim.reload()
outstanding_amount = get_outstanding_amount_for_claim(expense_claim)
self.assertEqual(outstanding_amount, 0)
self.assertEqual(total_amount_reimbursed, 5500)
self.assertEqual(expense_claim.total_amount_reimbursed, 5500)

def test_expense_claim_against_delivery_trip(self):
from erpnext.stock.doctype.delivery_trip.test_delivery_trip import (
Expand Down Expand Up @@ -644,17 +651,6 @@ def make_expense_claim(
return expense_claim


def get_outstanding_and_total_reimbursed_amounts(expense_claim):
outstanding_amount = flt(
frappe.db.get_value("Expense Claim", expense_claim.name, "total_sanctioned_amount")
) - flt(frappe.db.get_value("Expense Claim", expense_claim.name, "total_amount_reimbursed"))
total_amount_reimbursed = flt(
frappe.db.get_value("Expense Claim", expense_claim.name, "total_amount_reimbursed")
)

return outstanding_amount, total_amount_reimbursed


def make_payment_entry(expense_claim, amount):
from hrms.overrides.employee_payment_entry import get_payment_entry_for_employee

Expand Down

0 comments on commit 78f68f3

Please sign in to comment.