fix: Unaccrued interest after disbursal

This commit is contained in:
Deepesh Garg 2020-10-22 21:50:06 +05:30
parent 2c97244bad
commit cd2c90451e
3 changed files with 10 additions and 10 deletions

View File

@ -295,8 +295,7 @@
"default": "0",
"fieldname": "is_secured_loan",
"fieldtype": "Check",
"label": "Is Secured Loan",
"read_only": 1
"label": "Is Secured Loan"
},
{
"default": "0",
@ -351,7 +350,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2020-10-21 09:12:26.809228",
"modified": "2020-10-22 11:03:43.697394",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan",

View File

@ -210,21 +210,21 @@ def make_loan_interest_accrual_entry(args):
def get_no_of_days_for_interest_accural(loan, posting_date):
last_interest_accrual_date = get_last_accural_date_in_current_month(loan)
last_interest_accrual_date = get_last_accural_date(loan.name)
no_of_days = date_diff(posting_date or nowdate(), last_interest_accrual_date) + 1
return no_of_days
def get_last_accural_date_in_current_month(loan):
def get_last_accural_date(loan):
last_posting_date = frappe.db.sql(""" SELECT MAX(posting_date) from `tabLoan Interest Accrual`
WHERE loan = %s""", (loan.name))
WHERE loan = %s""", (loan))
if last_posting_date[0][0]:
# interest for last interest accrual date is already booked, so add 1 day
return add_days(last_posting_date[0][0], 1)
else:
return loan.disbursement_date
return frappe.db.get_value('Loan', loan, 'disbursement_date')
def days_in_year(year):
days = 365

View File

@ -14,7 +14,7 @@ from erpnext.controllers.accounts_controller import AccountsController
from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.loan_management.doctype.loan_security_shortfall.loan_security_shortfall import update_shortfall_status
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_demand_loans
from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import get_per_day_interest
from erpnext.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import get_per_day_interest, get_last_accural_date
class LoanRepayment(AccountsController):
@ -76,14 +76,15 @@ class LoanRepayment(AccountsController):
if self.total_interest_paid > self.interest_payable:
if not self.is_term_loan:
# get last loan interest accrual date
last_accrual_date = frappe.get_value('Loan Interest Accrual', {'loan': self.against_loan}, 'MAX(posting_date)')
last_accrual_date = get_last_accural_date(self.against_loan)
# get posting date upto which interest has to be accrued
per_day_interest = flt(get_per_day_interest(self.pending_principal_amount,
self.rate_of_interest, self.posting_date), 2)
no_of_days = flt(flt(self.total_interest_paid - self.interest_payable,
precision)/per_day_interest, 0)
precision)/per_day_interest, 0) - 1
posting_date = add_days(last_accrual_date, no_of_days)