fix: Loan repayment schedule date

This commit is contained in:
Deepesh Garg 2021-10-22 10:46:56 +05:30
parent 8116b9b62f
commit 1a5f0da6ca
2 changed files with 13 additions and 4 deletions

View File

@ -9,7 +9,7 @@ import math
import frappe
from frappe import _
from frappe.utils import add_months, flt, getdate, now_datetime, nowdate
from frappe.utils import add_months, flt, get_last_day, getdate, now_datetime, nowdate
from six import string_types
import erpnext
@ -102,7 +102,7 @@ class Loan(AccountsController):
"total_payment": total_payment,
"balance_loan_amount": balance_amount
})
next_payment_date = add_months(payment_date, 1)
next_payment_date = add_single_month(payment_date)
payment_date = next_payment_date
def set_repayment_period(self):
@ -391,3 +391,9 @@ def get_shortfall_applicants():
"value": len(applicants),
"fieldtype": "Int"
}
def add_single_month(date):
if getdate(date) == get_last_day(date):
return get_last_day(add_months(date, 1))
else:
return add_months(date, 1)

View File

@ -414,7 +414,10 @@ def get_penalty_details(against_loan):
return None, 0
def regenerate_repayment_schedule(loan):
from erpnext.loan_management.doctype.loan.loan import get_monthly_repayment_amount
from erpnext.loan_management.doctype.loan.loan import (
add_single_month,
get_monthly_repayment_amount,
)
loan_doc = frappe.get_doc('Loan', loan)
next_accrual_date = None
@ -456,7 +459,7 @@ def regenerate_repayment_schedule(loan):
"total_payment": total_payment,
"balance_loan_amount": balance_amount
})
next_payment_date = add_months(payment_date, 1)
next_payment_date = add_single_month(payment_date)
payment_date = next_payment_date
loan_doc.save()