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 before_save(self): gold_loan = frappe.get_doc('Gold Loan', self.loan) if not self.mode_of_payment: self.mode_of_payment = gold_loan.mode_of_payment if not self.payment_account: self.payment_account = get_bank_cash_account( self.mode_of_payment, self.company ).get('account') if not self.loan_account: self.loan_account = gold_loan.loan_account if not self.interest_income_account: self.interest_income_account = gold_loan.interest_income_account outstanding = get_outstanding( self.loan, posting_date=self.posting_date ) interest = outstanding * gold_loan.interest / 100.0 self.total_interest = self.interest_months * interest if self.interest_months > 0: self.make_interests(gold_loan, interest) self.total_amount = self.capital + self.total_interest
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'), ]
def before_save(self): gold_loan = frappe.get_doc('Gold Loan', self.loan) if not self.mode_of_payment: self.mode_of_payment = gold_loan.mode_of_payment if not self.payment_account: self.payment_account = get_bank_cash_account( self.mode_of_payment, self.company ).get('account') if not self.loan_account: self.loan_account = gold_loan.loan_account if not self.interest_income_account: self.interest_income_account = gold_loan.interest_income_account outstanding = get_outstanding( self.loan, posting_date=self.posting_date ) interest = outstanding * gold_loan.interest / 100.0 self.total_interest = cint(self.interest_months) * interest if not self.capital_amount and not self.total_interest: return frappe.throw('Cannot transaction with zero amount') self.interests = [] if self.interest_months > 0: self.make_interests(gold_loan, interest) self.total_amount = self.capital_amount + self.total_interest
def make_foreclosure_jv(loan_name, posting_date): loan = frappe.get_doc('Gold Loan', loan_name) je = frappe.new_doc('Journal Entry') je.update({ 'title': loan.customer, 'voucher_type': 'Journal Entry', 'company': loan.company, 'posting_date': posting_date, 'user_remark': 'Loan foreclosed', }) outstanding = get_outstanding(loan_name) je.set('accounts', [ { 'account': loan.loan_account, 'credit_in_account_currency': outstanding, 'reference_type': 'Gold Loan', 'reference_name': loan_name, }, { 'account': frappe.get_value( 'MSS Loan Settings', None, 'foreclosed_collateral_account' ), 'debit_in_account_currency': outstanding, 'reference_type': 'Gold Loan', 'reference_name': loan_name, }, ]) je.insert() je.submit() loan.update({ 'foreclosure_jv': je.name, 'status': 'Foreclosed', }) loan.save() return je.name
def validate(self): outstanding = get_outstanding( self.loan, posting_date=self.posting_date ) if self.capital > outstanding: frappe.throw('Capital amount cannot exceed outstanding amount')