Skip to content

Commit

Permalink
Merge pull request frappe#2283 from Nihantra-Patel/fix_loan_repayment
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman authored Oct 15, 2024
2 parents b742bc4 + 6d5f998 commit 3bff87b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ def make_bank_entry(self, for_withheld_salaries=False):

salary_slip_total -= salary_detail.amount

salary_slip_total -= flt(salary_detail.get("total_loan_repayment"))

bank_entry = None
if salary_slip_total > 0:
remark = "withheld salaries" if for_withheld_salaries else "salaries"
Expand All @@ -946,6 +948,7 @@ def get_salary_slip_details(self, for_withheld_salaries=False):
SalarySlip.employee,
SalarySlip.salary_structure,
SalarySlip.salary_withholding_cycle,
SalarySlip.total_loan_repayment,
SalaryDetail.salary_component,
SalaryDetail.amount,
SalaryDetail.parentfield,
Expand Down
35 changes: 35 additions & 0 deletions hrms/payroll/doctype/payroll_entry/test_payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,41 @@ def test_validate_attendance(self):
employees = payroll_entry.get_employees_with_unmarked_attendance()
self.assertFalse(employees)

@if_lending_app_installed
@change_settings("Payroll Settings", {"process_payroll_accounting_entry_based_on_employee": 0})
def test_loan_repayment_from_salary(self):
from lending.loan_management.doctype.loan.test_loan import make_loan_disbursement_entry
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
process_loan_interest_accrual_for_term_loans,
)

frappe.db.delete("Loan")
applicant, branch, currency, payroll_payable_account = setup_lending()

loan = create_loan_for_employee(applicant)
loan_doc = frappe.get_doc("Loan", loan.name)
loan_doc.repay_from_salary = 1
loan_doc.save()

make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=add_months(nowdate(), -1))
process_loan_interest_accrual_for_term_loans(posting_date=nowdate())

dates = get_start_end_dates("Monthly", nowdate())
payroll_entry = make_payroll_entry(
company="_Test Company",
start_date=dates.start_date,
payable_account=payroll_payable_account,
currency=currency,
end_date=dates.end_date,
branch=branch,
cost_center="Main - _TC",
payment_account="Cash - _TC",
total_loan_repayment=loan.monthly_repayment_amount,
)

payroll_entry.make_bank_entry()
submit_bank_entry(payroll_entry.name)


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

0 comments on commit 3bff87b

Please sign in to comment.