diff --git a/erpnext/loan_management/doctype/loan/loan.json b/erpnext/loan_management/doctype/loan/loan.json index 0e8feba2f12..b0edfcfece0 100644 --- a/erpnext/loan_management/doctype/loan/loan.json +++ b/erpnext/loan_management/doctype/loan/loan.json @@ -17,6 +17,7 @@ "posting_date", "status", "repay_from_salary", + "manually_update_paid_amount_in_salary_slip", "section_break_8", "loan_type", "loan_amount", @@ -410,16 +411,23 @@ "fieldname": "is_npa", "fieldtype": "Check", "label": "Is NPA" + }, + { + "allow_on_submit": 1, + "default": "0", + "depends_on": "repay_from_salary", + "fieldname": "manually_update_paid_amount_in_salary_slip", + "fieldtype": "Check", + "label": "Manually Update Paid Amount in Salary Slip" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2022-06-30 12:04:13.728880", + "modified": "2022-09-12 03:36:49.145014", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan", - "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -445,6 +453,5 @@ "search_fields": "posting_date", "sort_field": "creation", "sort_order": "DESC", - "states": [], "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 14a2a3ae398..5442bf201c8 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -587,7 +587,7 @@ class SalarySlip(TransactionBase): if self.salary_structure: self.calculate_component_amounts("deductions") - self.set_loan_repayment() + self.add_applicable_loans() self.set_precision_for_component_amounts() self.set_net_pay() @@ -1370,44 +1370,33 @@ class SalarySlip(TransactionBase): return joining_date, relieving_date - def set_loan_repayment(self): + def add_applicable_loans(self): self.total_loan_repayment = 0 self.total_interest_amount = 0 self.total_principal_amount = 0 - self.set("loans", []) + loans = [d.loan for d in self.get("loans")] + for loan in self.get_loan_details(): - amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment") - - if (amounts["interest_amount"] or amounts["payable_principal_amount"]) and ( - amounts["payable_principal_amount"] + amounts["interest_amount"] - > amounts["written_off_amount"] - ): - - if amounts["interest_amount"] > amounts["written_off_amount"]: - amounts["interest_amount"] -= amounts["written_off_amount"] - amounts["written_off_amount"] = 0 - else: - amounts["written_off_amount"] -= amounts["interest_amount"] - amounts["interest_amount"] = 0 - - if amounts["payable_principal_amount"] > amounts["written_off_amount"]: - amounts["payable_principal_amount"] -= amounts["written_off_amount"] - amounts["written_off_amount"] = 0 - else: - amounts["written_off_amount"] -= amounts["payable_principal_amount"] - amounts["payable_principal_amount"] = 0 - - self.append( - "loans", - { - "loan": loan.name, - "interest_amount": amounts["interest_amount"], - "principal_amount": amounts["payable_principal_amount"], - "loan_account": loan.loan_account, - "interest_income_account": loan.interest_income_account, - }, - ) + if loan.name not in loans: + amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment") + if ( + amounts["interest_amount"] + amounts["payable_principal_amount"] + > amounts["written_off_amount"] + ): + self.append( + "loans", + { + "loan": loan.name, + "interest_amount": amounts["interest_amount"], + "principal_amount": amounts["payable_principal_amount"], + "total_payment": amounts["interest_amount"] + amounts["payable_principal_amount"] + if not loan.manually_update_paid_amount_in_salary_slip + else 0, + "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") @@ -1432,7 +1421,14 @@ class SalarySlip(TransactionBase): def get_loan_details(self): loan_details = frappe.get_all( "Loan", - fields=["name", "interest_income_account", "loan_account", "loan_type", "is_term_loan"], + fields=[ + "name", + "interest_income_account", + "loan_account", + "loan_type", + "is_term_loan", + "manually_update_paid_amount_in_salary_slip", + ], filters={ "applicant": self.employee, "docstatus": 1,