def update_loan(self): """ Updates foreclosure date and status of the Gold Loan. Also works for on cancel because paid_interests contains only items with docstatus = 1 and this method is run after the cancel is complete """ loan = frappe.get_doc('Gold Loan', self.loan) paid_interests = get_paid_interests(self.loan) months_to_foreclosure = frappe.get_value( 'MSS Loan Settings', None, 'months_to_foreclosure' ) loan.foreclosure_date = add_months( loan.posting_date, cint(months_to_foreclosure) + paid_interests.count ) outstanding = get_outstanding( self.loan, posting_date=self.posting_date ) if outstanding == 0: loan.status = 'Repaid' elif loan.status != 'Open': loan.status = 'Open' loan.save()
def make_interests(self, loan, interest_amount): paid_interests = get_paid_interests( self.loan, posting_date=self.posting_date ) interest_days = map( lambda x: add_months(loan.posting_date, x), range( paid_interests.count, self.interest_months + paid_interests.count ) ) for day in interest_days: self.append('interests', { 'period_label': '', 'period_code': make_period(day), 'interest_amount': interest_amount })
def fn(loan): paid_interests = get_paid_interests(loan.name) latest = paid_interests.get('latest') last_paid_date = latest.get('period_code').split(' - ')[0] \ if latest else add_months(loan.posting_date, -1) unpaid_months = month_diff(current_date, last_paid_date) - 1 outstanding = get_outstanding(loan.name) interest = outstanding * loan.interest / 100.0 print(latest) return [ loan.name, loan.posting_date, loan.customer, loan.principal, loan.foreclosure_date, outstanding, interest * unpaid_months, interest and unpaid_months, latest and latest.get('posting_date'), latest and latest.get('period_label'), ]