mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 20:59:11 +00:00
fix: Employee loan test case and other fixes
This commit is contained in:
@@ -13,7 +13,7 @@ from erpnext.hr.doctype.salary_slip.test_salary_slip import get_salary_component
|
||||
make_earning_salary_component, make_deduction_salary_component
|
||||
from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||
from erpnext.loan_management.doctype.loan.test_loan import create_loan, make_loan_disbursement_entry
|
||||
from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import make_accrual_interest_entry_for_term_loans
|
||||
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_term_loans
|
||||
|
||||
class TestPayrollEntry(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -81,7 +81,7 @@ class TestPayrollEntry(unittest.TestCase):
|
||||
|
||||
make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=add_months(nowdate(), -1))
|
||||
|
||||
make_accrual_interest_entry_for_term_loans(posting_date=nowdate())
|
||||
process_loan_interest_accrual_for_term_loans(posting_date=nowdate())
|
||||
|
||||
|
||||
dates = get_start_end_dates('Monthly', nowdate())
|
||||
|
||||
@@ -755,30 +755,43 @@ class SalarySlip(TransactionBase):
|
||||
d.amount = self.get_amount_based_on_payment_days(d, joining_date, relieving_date)[0]
|
||||
|
||||
def set_loan_repayment(self):
|
||||
self.set('loans', [])
|
||||
self.total_loan_repayment = 0
|
||||
self.total_interest_amount = 0
|
||||
self.total_principal_amount = 0
|
||||
|
||||
for loan in self.get_loan_details():
|
||||
if not self.get('loans'):
|
||||
for loan in self.get_loan_details():
|
||||
|
||||
amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment")
|
||||
amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment")
|
||||
|
||||
total_payment = amounts['interest_amount'] + amounts['payable_principal_amount']
|
||||
if amounts['interest_amount'] or amounts['payable_principal_amount']:
|
||||
self.append('loans', {
|
||||
'loan': loan.name,
|
||||
'total_payment': amounts['interest_amount'] + amounts['payable_principal_amount'],
|
||||
'interest_amount': amounts['interest_amount'],
|
||||
'principal_amount': amounts['payable_principal_amount'],
|
||||
'loan_account': loan.loan_account,
|
||||
'interest_income_account': loan.interest_income_account
|
||||
})
|
||||
|
||||
if total_payment:
|
||||
self.append('loans', {
|
||||
'loan': loan.name,
|
||||
'total_payment': total_payment,
|
||||
'interest_amount': amounts['interest_amount'],
|
||||
'principal_amount': amounts['payable_principal_amount'],
|
||||
'loan_account': loan.loan_account,
|
||||
'interest_income_account': loan.interest_income_account
|
||||
})
|
||||
for payment in self.get('loans'):
|
||||
amounts = calculate_amounts(payment.loan, self.posting_date, "Regular Payment")
|
||||
|
||||
self.total_loan_repayment += total_payment
|
||||
self.total_interest_amount += amounts['interest_amount']
|
||||
self.total_principal_amount += amounts['payable_principal_amount']
|
||||
if payment.interest_amount > amounts['interest_amount']:
|
||||
frappe.throw(_("""Row {0}: Paid Interest amount {1} is greater than pending interest amount {2}
|
||||
against loan {3}""").format(payment.idx, frappe.bold(payment.interest_amount),
|
||||
frappe.bold(amounts['interest_amount']), frappe.bold(payment.loan)))
|
||||
|
||||
if payment.principal_amount > amounts['payable_principal_amount']:
|
||||
frappe.throw(_("""Row {0}: Paid Principal amount {1} is greater than pending principal amount {2}
|
||||
against loan {3}""").format(payment.idx, frappe.bold(payment.principal_amount),
|
||||
frappe.bold(amounts['payable_principal_amount']), frappe.bold(payment.loan)))
|
||||
|
||||
payment.total_payment = payment.interest_amount + payment.principal_amount
|
||||
self.total_interest_amount += payment.interest_amount
|
||||
self.total_principal_amount += payment.principal_amount
|
||||
|
||||
self.total_loan_repayment = self.total_interest_amount + self.total_principal_amount
|
||||
|
||||
def get_loan_details(self):
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
|
||||
def test_loan_repayment_salary_slip(self):
|
||||
from erpnext.loan_management.doctype.loan.test_loan import create_loan_type, create_loan, make_loan_disbursement_entry, create_loan_accounts
|
||||
from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import make_accrual_interest_entry_for_term_loans
|
||||
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_term_loans
|
||||
|
||||
applicant = make_employee("test_loanemployee@salary.com", company="_Test Company")
|
||||
|
||||
@@ -166,7 +166,7 @@ class TestSalarySlip(unittest.TestCase):
|
||||
|
||||
make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=add_months(nowdate(), -1))
|
||||
|
||||
make_accrual_interest_entry_for_term_loans(posting_date=nowdate())
|
||||
process_loan_interest_accrual_for_term_loans(posting_date=nowdate())
|
||||
|
||||
ss = make_employee_salary_slip("test_loanemployee@salary.com", "Monthly")
|
||||
ss.submit()
|
||||
|
||||
Reference in New Issue
Block a user