Skip to content

Commit

Permalink
fix: correct bank entry calculation and update the testcase
Browse files Browse the repository at this point in the history
(cherry picked from commit 44cdcc7)

# Conflicts:
#	hrms/payroll/doctype/payroll_entry/test_payroll_entry.py
  • Loading branch information
Nihantra-Patel authored and mergify[bot] committed Oct 28, 2024
1 parent 4d93cfa commit f0be056
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,8 @@ def make_bank_entry(self, for_withheld_salaries=False):

salary_slip_total -= salary_detail.amount

total_loan_repayment = sum(
flt(slip.get("total_loan_repayment", 0))
for slip in {slip["name"]: slip for slip in salary_slips}.values()
)
unique_salary_slips = {slip["name"]: slip for slip in salary_slips}.values()
total_loan_repayment = sum(flt(slip.get("total_loan_repayment", 0)) for slip in unique_salary_slips)
salary_slip_total -= total_loan_repayment

bank_entry = None
Expand Down
16 changes: 16 additions & 0 deletions hrms/payroll/doctype/payroll_entry/test_payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
from dateutil.relativedelta import relativedelta

import frappe
<<<<<<< HEAD
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, add_months, cstr
=======
from frappe.tests import IntegrationTestCase, change_settings
from frappe.utils import add_days, add_months, cstr, flt
>>>>>>> 44cdcc7df (fix: correct bank entry calculation and update the testcase)

import erpnext
from erpnext.accounts.utils import get_fiscal_year, getdate, nowdate
Expand Down Expand Up @@ -749,9 +754,20 @@ def test_loan_repayment_from_salary(self):
total_loan_repayment=loan.monthly_repayment_amount,
)

salary_slip_name = frappe.db.get_value("Salary Slip", {"payroll_entry": payroll_entry.name}, "name")
salary_slip = frappe.get_doc("Salary Slip", salary_slip_name)
payroll_entry.reload()

initial_gross_pay = flt(salary_slip.gross_pay) - flt(salary_slip.total_deduction)
loan_repayment_amount = flt(salary_slip.total_loan_repayment)
expected_net_pay = initial_gross_pay - loan_repayment_amount

payroll_entry.make_bank_entry()
submit_bank_entry(payroll_entry.name)

salary_slip.reload()
self.assertEqual(salary_slip.net_pay, expected_net_pay)


def get_payroll_entry(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit f0be056

Please sign in to comment.