Merge pull request #29169 from deepeshgarg007/loan_repayment_salary_slip

fix: GL Entries for loan repayment via Salary
This commit is contained in:
Deepesh Garg 2022-01-07 12:54:25 +05:30 committed by GitHub
commit a456cf4225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 64 deletions

View File

@ -13,8 +13,10 @@
"column_break_3",
"company",
"posting_date",
"is_term_loan",
"rate_of_interest",
"payroll_payable_account",
"is_term_loan",
"repay_from_salary",
"payment_details_section",
"due_date",
"pending_principal_amount",
@ -243,15 +245,31 @@
"label": "Total Penalty Paid",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"depends_on": "eval:doc.repay_from_salary",
"fieldname": "payroll_payable_account",
"fieldtype": "Link",
"label": "Payroll Payable Account",
"mandatory_depends_on": "eval:doc.repay_from_salary",
"options": "Account"
},
{
"default": "0",
"fetch_from": "against_loan.repay_from_salary",
"fieldname": "repay_from_salary",
"fieldtype": "Check",
"label": "Repay From Salary"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2021-04-19 18:10:00.935364",
"modified": "2022-01-06 01:51:06.707782",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Repayment",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
@ -287,5 +305,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@ -320,74 +320,79 @@ class LoanRepayment(AccountsController):
else:
remarks = _("Repayment against Loan: ") + self.against_loan
if not loan_details.repay_from_salary:
if self.total_penalty_paid:
gle_map.append(
self.get_gl_dict({
"account": loan_details.loan_account,
"against": loan_details.payment_account,
"debit": self.total_penalty_paid,
"debit_in_account_currency": self.total_penalty_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": _("Penalty against loan:") + self.against_loan,
"cost_center": self.cost_center,
"party_type": self.applicant_type,
"party": self.applicant,
"posting_date": getdate(self.posting_date)
})
)
gle_map.append(
self.get_gl_dict({
"account": loan_details.penalty_income_account,
"against": loan_details.payment_account,
"credit": self.total_penalty_paid,
"credit_in_account_currency": self.total_penalty_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": _("Penalty against loan:") + self.against_loan,
"cost_center": self.cost_center,
"posting_date": getdate(self.posting_date)
})
)
gle_map.append(
self.get_gl_dict({
"account": loan_details.payment_account,
"against": loan_details.loan_account + ", " + loan_details.interest_income_account
+ ", " + loan_details.penalty_income_account,
"debit": self.amount_paid,
"debit_in_account_currency": self.amount_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": remarks,
"cost_center": self.cost_center,
"posting_date": getdate(self.posting_date)
})
)
if self.repay_from_salary:
payment_account = self.payroll_payable_account
else:
payment_account = loan_details.payment_account
if self.total_penalty_paid:
gle_map.append(
self.get_gl_dict({
"account": loan_details.loan_account,
"party_type": loan_details.applicant_type,
"party": loan_details.applicant,
"against": loan_details.payment_account,
"credit": self.amount_paid,
"credit_in_account_currency": self.amount_paid,
"debit": self.total_penalty_paid,
"debit_in_account_currency": self.total_penalty_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": remarks,
"remarks": _("Penalty against loan:") + self.against_loan,
"cost_center": self.cost_center,
"party_type": self.applicant_type,
"party": self.applicant,
"posting_date": getdate(self.posting_date)
})
)
gle_map.append(
self.get_gl_dict({
"account": loan_details.penalty_income_account,
"against": payment_account,
"credit": self.total_penalty_paid,
"credit_in_account_currency": self.total_penalty_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": _("Penalty against loan:") + self.against_loan,
"cost_center": self.cost_center,
"posting_date": getdate(self.posting_date)
})
)
if gle_map:
make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj, merge_entries=False)
gle_map.append(
self.get_gl_dict({
"account": payment_account,
"against": loan_details.loan_account + ", " + loan_details.interest_income_account
+ ", " + loan_details.penalty_income_account,
"debit": self.amount_paid,
"debit_in_account_currency": self.amount_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": remarks,
"cost_center": self.cost_center,
"posting_date": getdate(self.posting_date)
})
)
gle_map.append(
self.get_gl_dict({
"account": loan_details.loan_account,
"party_type": loan_details.applicant_type,
"party": loan_details.applicant,
"against": payment_account,
"credit": self.amount_paid,
"credit_in_account_currency": self.amount_paid,
"against_voucher_type": "Loan",
"against_voucher": self.against_loan,
"remarks": remarks,
"cost_center": self.cost_center,
"posting_date": getdate(self.posting_date)
})
)
if gle_map:
make_gl_entries(gle_map, cancel=cancel, adv_adj=adv_adj, merge_entries=False)
def create_repayment_entry(loan, applicant, company, posting_date, loan_type,
payment_type, interest_payable, payable_principal_amount, amount_paid, penalty_amount=None):
payment_type, interest_payable, payable_principal_amount, amount_paid, penalty_amount=None,
payroll_payable_account=None):
lr = frappe.get_doc({
"doctype": "Loan Repayment",
@ -400,7 +405,8 @@ def create_repayment_entry(loan, applicant, company, posting_date, loan_type,
"interest_payable": interest_payable,
"payable_principal_amount": payable_principal_amount,
"amount_paid": amount_paid,
"loan_type": loan_type
"loan_type": loan_type,
"payroll_payable_account": payroll_payable_account
}).insert()
return lr

View File

@ -1142,15 +1142,17 @@ class SalarySlip(TransactionBase):
})
def make_loan_repayment_entry(self):
payroll_payable_account = get_payroll_payable_account(self.company, self.payroll_entry)
for loan in self.loans:
repayment_entry = create_repayment_entry(loan.loan, self.employee,
self.company, self.posting_date, loan.loan_type, "Regular Payment", loan.interest_amount,
loan.principal_amount, loan.total_payment)
if loan.total_payment:
repayment_entry = create_repayment_entry(loan.loan, self.employee,
self.company, self.posting_date, loan.loan_type, "Regular Payment", loan.interest_amount,
loan.principal_amount, loan.total_payment, payroll_payable_account=payroll_payable_account)
repayment_entry.save()
repayment_entry.submit()
repayment_entry.save()
repayment_entry.submit()
frappe.db.set_value("Salary Slip Loan", loan.name, "loan_repayment_entry", repayment_entry.name)
frappe.db.set_value("Salary Slip Loan", loan.name, "loan_repayment_entry", repayment_entry.name)
def cancel_loan_repayment_entry(self):
for loan in self.loans:
@ -1384,3 +1386,11 @@ def get_salary_component_data(component):
],
as_dict=1,
)
def get_payroll_payable_account(company, payroll_entry):
if payroll_entry:
payroll_payable_account = frappe.db.get_value('Payroll Entry', payroll_entry, 'payroll_payable_account')
else:
payroll_payable_account = frappe.db.get_value('Company', company, 'default_payroll_payable_account')
return payroll_payable_account

View File

@ -380,7 +380,7 @@ class TestSalarySlip(unittest.TestCase):
make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR',
payroll_period=payroll_period)
frappe.db.sql("delete from tabLoan")
frappe.db.sql("delete from tabLoan where applicant = 'test_loan_repayment_salary_slip@salary.com'")
loan = create_loan(applicant, "Car Loan", 11000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1))
loan.repay_from_salary = 1
loan.submit()