Example #1
0
    def test_loan_security_unpledge(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

        loan_application = create_loan_application("_Test Company",
                                                   self.applicant2,
                                                   "Demand Loan", pledge)
        create_pledge(loan_application)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date="2019-10-01")
        loan.submit()

        self.assertEqual(loan.loan_amount, 1000000)

        first_date = "2019-10-01"
        last_date = "2019-10-30"

        no_of_days = date_diff(last_date, first_date) + 1

        no_of_days += 5

        accrued_interest_amount = (
            loan.loan_amount * loan.rate_of_interest *
            no_of_days) / (days_in_year(get_datetime(first_date).year) * 100)

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)
        process_loan_interest_accrual_for_demand_loans(posting_date=last_date)

        repayment_entry = create_repayment_entry(
            loan.name,
            self.applicant2,
            add_days(last_date, 5),
            flt(loan.loan_amount + accrued_interest_amount),
        )
        repayment_entry.submit()

        request_loan_closure(loan.name)
        loan.load_from_db()
        self.assertEqual(loan.status, "Loan Closure Requested")

        unpledge_request = unpledge_security(loan=loan.name, save=1)
        unpledge_request.submit()
        unpledge_request.status = "Approved"
        unpledge_request.save()
        loan.load_from_db()

        pledged_qty = get_pledged_security_qty(loan.name)

        self.assertEqual(loan.status, "Closed")
        self.assertEqual(sum(pledged_qty.values()), 0)

        amounts = amounts = calculate_amounts(loan.name,
                                              add_days(last_date, 5))
        self.assertEqual(amounts["pending_principal_amount"], 0)
        self.assertEqual(amounts["payable_principal_amount"], 0.0)
        self.assertEqual(amounts["interest_amount"], 0)
Example #2
0
    def test_loan_write_off_limit(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

        loan_application = create_loan_application("_Test Company",
                                                   self.applicant2,
                                                   "Demand Loan", pledge)
        create_pledge(loan_application)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date="2019-10-01")
        loan.submit()

        self.assertEqual(loan.loan_amount, 1000000)

        first_date = "2019-10-01"
        last_date = "2019-10-30"

        no_of_days = date_diff(last_date, first_date) + 1
        no_of_days += 5

        accrued_interest_amount = (
            loan.loan_amount * loan.rate_of_interest *
            no_of_days) / (days_in_year(get_datetime(first_date).year) * 100)

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)
        process_loan_interest_accrual_for_demand_loans(posting_date=last_date)

        # repay 50 less so that it can be automatically written off
        repayment_entry = create_repayment_entry(
            loan.name,
            self.applicant2,
            add_days(last_date, 5),
            flt(loan.loan_amount + accrued_interest_amount - 50),
        )

        repayment_entry.submit()

        amount = frappe.db.get_value("Loan Interest Accrual",
                                     {"loan": loan.name},
                                     ["sum(paid_interest_amount)"])

        self.assertEqual(flt(amount, 0), flt(accrued_interest_amount, 0))
        self.assertEqual(flt(repayment_entry.penalty_amount, 5), 0)

        amounts = calculate_amounts(loan.name, add_days(last_date, 5))
        self.assertEqual(flt(amounts["pending_principal_amount"], 0), 50)

        request_loan_closure(loan.name)
        loan.load_from_db()
        self.assertEqual(loan.status, "Loan Closure Requested")
Example #3
0
    def test_loan_closure(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

        loan_application = create_loan_application("_Test Company",
                                                   self.applicant2,
                                                   "Demand Loan", pledge)
        create_pledge(loan_application)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date="2019-10-01")
        loan.submit()

        self.assertEqual(loan.loan_amount, 1000000)

        first_date = "2019-10-01"
        last_date = "2019-10-30"

        no_of_days = date_diff(last_date, first_date) + 1

        # Adding 5 since repayment is made 5 days late after due date
        # and since payment type is loan closure so interest should be considered for those
        # 5 days as well though in grace period
        no_of_days += 5

        accrued_interest_amount = (
            loan.loan_amount * loan.rate_of_interest *
            no_of_days) / (days_in_year(get_datetime(first_date).year) * 100)

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)
        process_loan_interest_accrual_for_demand_loans(posting_date=last_date)

        repayment_entry = create_repayment_entry(
            loan.name,
            self.applicant2,
            add_days(last_date, 5),
            flt(loan.loan_amount + accrued_interest_amount),
        )

        repayment_entry.submit()

        amount = frappe.db.get_value("Loan Interest Accrual",
                                     {"loan": loan.name},
                                     ["sum(paid_interest_amount)"])

        self.assertEqual(flt(amount, 0), flt(accrued_interest_amount, 0))
        self.assertEqual(flt(repayment_entry.penalty_amount, 5), 0)

        request_loan_closure(loan.name)
        loan.load_from_db()
        self.assertEqual(loan.status, "Loan Closure Requested")
Example #4
0
    def test_pending_loan_amount_after_closure_request(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

        loan_application = create_loan_application('_Test Company',
                                                   self.applicant2,
                                                   'Demand Loan', pledge)
        create_pledge(loan_application)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date='2019-10-01')
        loan.submit()

        self.assertEquals(loan.loan_amount, 1000000)

        first_date = '2019-10-01'
        last_date = '2019-10-30'

        no_of_days = date_diff(last_date, first_date) + 1

        no_of_days += 5

        accrued_interest_amount = (loan.loan_amount * loan.rate_of_interest * no_of_days) \
            / (days_in_year(get_datetime(first_date).year) * 100)

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)
        process_loan_interest_accrual_for_demand_loans(posting_date=last_date)

        amounts = calculate_amounts(loan.name, add_days(last_date, 5))

        repayment_entry = create_repayment_entry(
            loan.name, self.applicant2, add_days(last_date, 5),
            flt(loan.loan_amount + accrued_interest_amount))
        repayment_entry.submit()

        amounts = frappe.db.get_value(
            'Loan Interest Accrual', {'loan': loan.name},
            ['paid_interest_amount', 'paid_principal_amount'])

        request_loan_closure(loan.name)
        loan.load_from_db()
        self.assertEquals(loan.status, "Loan Closure Requested")

        amounts = calculate_amounts(loan.name, add_days(last_date, 5))
        self.assertEqual(amounts['pending_principal_amount'], 0.0)