Esempio n. 1
0
    def test_partial_loan_repayment(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant2, pledges)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))

        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

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

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)

        process_loan_interest_accrual(posting_date=add_days(first_date, 15))
        process_loan_interest_accrual(posting_date=add_days(first_date, 30))

        repayment_entry = create_repayment_entry(loan.name, self.applicant2,
                                                 add_days(last_date, 1),
                                                 "Regular Payment", 6500)
        repayment_entry.save()
        repayment_entry.submit()

        penalty_amount = (accrued_interest_amount * 4 * 25) / (
            100 * days_in_year(get_datetime(first_date).year))

        lia1 = frappe.get_value("Loan Interest Accrual", {
            "loan": loan.name,
            "is_paid": 1
        }, 'name')
        lia2 = frappe.get_value("Loan Interest Accrual", {
            "loan": loan.name,
            "is_paid": 0
        }, 'name')

        self.assertTrue(lia1)
        self.assertTrue(lia2)
Esempio n. 2
0
    def test_regular_loan_repayment(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant2, pledges)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))

        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

        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, 10),
                                                 "Regular Payment", 111118.68)
        repayment_entry.save()
        repayment_entry.submit()

        penalty_amount = (accrued_interest_amount * 4 * 25) / (
            100 * days_in_year(get_datetime(first_date).year))
        self.assertEquals(flt(repayment_entry.penalty_amount, 2),
                          flt(penalty_amount, 2))

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

        loan.load_from_db()

        self.assertEquals(amounts[0], repayment_entry.interest_payable)
        self.assertEquals(
            flt(loan.total_principal_paid, 2),
            flt(repayment_entry.amount_paid - penalty_amount - amounts[0], 2))
Esempio n. 3
0
    def test_loan_closure_repayment(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant2, pledges)
        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))
        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

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

        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), "Loan Closure",
            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'])

        unaccrued_interest_amount =  (loan.loan_amount * loan.rate_of_interest * 6) \
         / (days_in_year(get_datetime(first_date).year) * 100)

        self.assertEquals(flt(amounts[0] + unaccrued_interest_amount, 3),
                          flt(accrued_interest_amount, 3))
        self.assertEquals(flt(repayment_entry.penalty_amount, 5), 0)

        loan.load_from_db()
        self.assertEquals(loan.status, "Loan Closure Requested")
Esempio n. 4
0
    def test_accumulated_amounts(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

        loan_application = create_loan_application("_Test Company",
                                                   self.applicant,
                                                   "Demand Loan", pledge)
        create_pledge(loan_application)
        loan = create_demand_loan(self.applicant,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date=get_first_day(nowdate()))
        loan.submit()

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

        no_of_days = date_diff(last_date, first_date) + 1
        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)
        loan_interest_accrual = frappe.get_doc("Loan Interest Accrual",
                                               {"loan": loan.name})

        self.assertEqual(flt(loan_interest_accrual.interest_amount, 0),
                         flt(accrued_interest_amount, 0))

        next_start_date = "2019-10-31"
        next_end_date = "2019-11-29"

        no_of_days = date_diff(next_end_date, next_start_date) + 1
        process = process_loan_interest_accrual_for_demand_loans(
            posting_date=next_end_date)
        new_accrued_interest_amount = (
            loan.loan_amount * loan.rate_of_interest *
            no_of_days) / (days_in_year(get_datetime(first_date).year) * 100)

        total_pending_interest_amount = flt(
            accrued_interest_amount + new_accrued_interest_amount, 0)

        loan_interest_accrual = frappe.get_doc(
            "Loan Interest Accrual", {
                "loan": loan.name,
                "process_loan_interest_accrual": process
            })
        self.assertEqual(
            flt(loan_interest_accrual.total_pending_interest_amount, 0),
            total_pending_interest_amount)
Esempio n. 5
0
    def test_partial_unaccrued_interest_payment(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.5

        # get partial unaccrued interest amount
        paid_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),
                                                 paid_amount)

        repayment_entry.submit()
        repayment_entry.load_from_db()

        partial_accrued_interest_amount = (
            loan.loan_amount * loan.rate_of_interest *
            5) / (days_in_year(get_datetime(first_date).year) * 100)

        interest_amount = flt(
            amounts["interest_amount"] + partial_accrued_interest_amount, 2)
        self.assertEqual(flt(repayment_entry.total_interest_paid, 0),
                         flt(interest_amount, 0))
Esempio n. 6
0
    def test_regular_loan_repayment(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant2, pledges)

        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))

        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

        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(posting_date=last_date)

        repayment_entry = create_repayment_entry(loan.name, self.applicant2,
                                                 add_days(last_date, 10),
                                                 "Regular Payment", 111118.68)
        repayment_entry.save()

        penalty_amount = (accrued_interest_amount * 5 * 25) / (
            100 * days_in_year(get_datetime(first_date).year))

        self.assertEquals(flt(repayment_entry.interest_payable, 2),
                          flt(accrued_interest_amount, 2))
        self.assertEquals(flt(repayment_entry.penalty_amount, 2),
                          flt(penalty_amount, 2))

        repayment_entry.submit()
Esempio n. 7
0
	def test_loan_interest_accural(self):
		pledge = [{
			"loan_security": "Test Security 1",
			"qty": 4000.00
		}]

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

		loan = create_demand_loan(self.applicant, "Demand Loan", loan_application,
			posting_date=get_first_day(nowdate()))

		loan.submit()

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

		no_of_days = date_diff(last_date, first_date) + 1

		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)

		loan_interest_accural = frappe.get_doc("Loan Interest Accrual", {'loan': loan.name})

		self.assertEquals(flt(loan_interest_accural.interest_amount, 2), flt(accrued_interest_amount, 2))
Esempio n. 8
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)
Esempio n. 9
0
    def test_loan_security_unpledge(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant2, pledges)
        loan = create_demand_loan(self.applicant2,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))
        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 += 6

        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, 6), "Loan Closure",
            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'])

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

        unpledge_request = create_loan_security_unpledge(loan.name,
                                                         loan.applicant_type,
                                                         loan.applicant,
                                                         loan.company,
                                                         as_dict=0)
        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.assertEquals(sum(pledged_qty.values()), 0)
Esempio n. 10
0
    def test_loan_amount_write_off(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 100 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 - 100),
        )

        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), 100)

        we = make_loan_write_off(loan.name,
                                 amount=amounts["pending_principal_amount"])
        we.submit()

        amounts = calculate_amounts(loan.name, add_days(last_date, 5))
        self.assertEqual(flt(amounts["pending_principal_amount"], 0), 0)
Esempio n. 11
0
    def test_regular_loan_repayment(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

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

        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, 10),
                                                 111119)
        repayment_entry.save()
        repayment_entry.submit()

        penalty_amount = (accrued_interest_amount * 5 * 25) / 100
        self.assertEquals(flt(repayment_entry.penalty_amount, 0),
                          flt(penalty_amount, 0))

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

        loan.load_from_db()

        total_interest_paid = amounts[0]['paid_interest_amount'] + \
            amounts[1]['paid_interest_amount']
        self.assertEquals(amounts[1]['paid_interest_amount'],
                          repayment_entry.interest_payable)
        self.assertEquals(
            flt(loan.total_principal_paid, 0),
            flt(
                repayment_entry.amount_paid - penalty_amount -
                total_interest_paid, 0))
Esempio n. 12
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=get_first_day(nowdate()))
        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 += 6

        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, 6), "Loan Closure",
            flt(loan.loan_amount + accrued_interest_amount))
        repayment_entry.submit()

        loan.load_from_db()
        self.assertEquals(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.assertEquals(sum(pledged_qty.values()), 0)

        amounts = amounts = calculate_amounts(loan.name,
                                              add_days(last_date,
                                                       6), "Regular Repayment")
        self.assertEqual(amounts['pending_principal_amount'], 0)
        self.assertEqual(amounts['payable_principal_amount'], 0)
        self.assertEqual(amounts['interest_amount'], 0)
Esempio n. 13
0
    def test_loan_topup(self):
        pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]

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

        loan = create_demand_loan(self.applicant,
                                  "Demand Loan",
                                  loan_application,
                                  posting_date=get_first_day(nowdate()))

        loan.submit()

        first_date = get_first_day(nowdate())
        last_date = get_last_day(nowdate())

        no_of_days = date_diff(last_date, first_date) + 1

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

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)

        process_loan_interest_accrual_for_demand_loans(
            posting_date=add_days(last_date, 1))

        # Should not be able to create loan disbursement entry before repayment
        self.assertRaises(frappe.ValidationError, make_loan_disbursement_entry,
                          loan.name, 500000, first_date)

        repayment_entry = create_repayment_entry(
            loan.name, self.applicant, add_days(get_last_day(nowdate()), 5),
            611095.89)

        repayment_entry.submit()
        loan.reload()

        # After repayment loan disbursement entry should go through
        make_loan_disbursement_entry(loan.name,
                                     500000,
                                     disbursement_date=add_days(last_date, 16))

        # check for disbursement accrual
        loan_interest_accrual = frappe.db.get_value(
            "Loan Interest Accrual", {
                "loan": loan.name,
                "accrual_type": "Disbursement"
            })

        self.assertTrue(loan_interest_accrual)
Esempio n. 14
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")
    def test_loan_topup(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50,
            "loan_security_price": 500.00
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant, pledges)

        loan = create_demand_loan(self.applicant,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))

        loan.submit()

        first_date = get_first_day(nowdate())
        last_date = get_last_day(nowdate())

        no_of_days = date_diff(last_date, first_date) + 1

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

        make_loan_disbursement_entry(loan.name,
                                     loan.loan_amount,
                                     disbursement_date=first_date)

        process_loan_interest_accrual(posting_date=add_days(last_date, 1))

        # Paid 511095.89 amount includes 5,00,000 principal amount and 11095.89 interest amount
        repayment_entry = create_repayment_entry(
            loan.name, self.applicant, add_days(get_last_day(nowdate()), 5),
            "Regular Payment", 611095.89)
        repayment_entry.submit()

        loan.reload()

        make_loan_disbursement_entry(loan.name,
                                     500000,
                                     disbursement_date=add_days(last_date, 16))

        total_principal_paid = loan.total_principal_paid

        loan.reload()

        # Loan Topup will result in decreasing the Total Principal Paid
        self.assertEqual(flt(loan.total_principal_paid, 2),
                         flt(total_principal_paid - 500000, 2))
Esempio n. 16
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.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)

        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.assertEqual(loan.status, "Loan Closure Requested")

        amounts = calculate_amounts(loan.name, add_days(last_date, 5))
        self.assertEqual(amounts["pending_principal_amount"], 0.0)
Esempio n. 17
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.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)

        # 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.assertEquals(flt(amount, 0), flt(accrued_interest_amount, 0))
        self.assertEquals(flt(repayment_entry.penalty_amount, 5), 0)

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

        request_loan_closure(loan.name)
        loan.load_from_db()
        self.assertEquals(loan.status, "Loan Closure Requested")
Esempio n. 18
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=get_first_day(nowdate()))
        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 += 6

        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, 6),
                                    "Regular Repayment")

        repayment_entry = create_repayment_entry(
            loan.name, self.applicant2, add_days(last_date, 6), "Loan Closure",
            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'])

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

        amounts = calculate_amounts(loan.name, add_days(last_date, 6),
                                    "Regular Repayment")
        self.assertEquals(amounts['pending_principal_amount'], 0.0)
Esempio n. 19
0
	def test_loan_topup(self):
		pledges = []
		pledges.append({
			"loan_security": "Test Security 1",
			"qty": 4000.00,
			"haircut": 50,
			"loan_security_price": 500.00
		})

		loan_security_pledge = create_loan_security_pledge(self.applicant, pledges)

		loan = create_demand_loan(self.applicant, "Demand Loan", loan_security_pledge.name,
			posting_date=get_first_day(nowdate()))

		loan.submit()

		first_date = get_first_day(nowdate())
		last_date = get_last_day(nowdate())

		no_of_days = date_diff(last_date, first_date) + 1

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

		make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date)

		process_loan_interest_accrual_for_demand_loans(posting_date=add_days(last_date, 1))

		# Should not be able to create loan disbursement entry before repayment
		self.assertRaises(frappe.ValidationError, make_loan_disbursement_entry, loan.name,
			500000, first_date)

		repayment_entry = create_repayment_entry(loan.name, self.applicant, add_days(get_last_day(nowdate()), 5),
			"Regular Payment", 611095.89)

		repayment_entry.submit()
		loan.reload()

		# After repayment loan disbursement entry should go through
		make_loan_disbursement_entry(loan.name, 500000, disbursement_date=add_days(last_date, 16))
    def test_loan_interest_accural(self):
        pledges = []
        pledges.append({
            "loan_security": "Test Security 1",
            "qty": 4000.00,
            "haircut": 50,
            "loan_security_price": 500.00
        })

        loan_security_pledge = create_loan_security_pledge(
            self.applicant, pledges)

        loan = create_demand_loan(self.applicant,
                                  "Demand Loan",
                                  loan_security_pledge.name,
                                  posting_date=get_first_day(nowdate()))

        loan.submit()

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

        no_of_days = date_diff(last_date, first_date) + 1

        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(posting_date=last_date)

        loan_interest_accural = frappe.get_doc("Loan Interest Accrual",
                                               {'loan': loan.name})

        self.assertEquals(flt(loan_interest_accural.interest_amount, 2),
                          flt(accrued_interest_amount, 2))