Skip to content

Commit

Permalink
Merge pull request #227 from RedCarpetUp/gross_principal_column
Browse files Browse the repository at this point in the history
Added sub_product_type and gross_principal column
  • Loading branch information
raghavio authored May 26, 2021
2 parents b8214f7 + b4dec00 commit 9bc7956
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/rush/card/base_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def create(cls, session: Session, **kwargs) -> Loan:
# Don't want to overwrite default value in case of None.
if kwargs.get("interest_free_period_in_days"):
loan.interest_free_period_in_days = kwargs.get("interest_free_period_in_days")
loan.sub_product_type = "card"
return loan

def reinstate_limit_on_payment(self, event: LedgerTriggerEvent, amount: Decimal) -> None:
Expand Down
1 change: 1 addition & 0 deletions src/rush/card/reset_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def create(cls, session: Session, **kwargs) -> Loan:
loan.interest_type = "flat"
loan.downpayment_percent = Decimal(0)
loan.can_close_early = False
loan.sub_product_type = "tenure_loan"

bill_start_date, bill_close_date = cls.bill_class.calculate_bill_start_and_close_date(
first_bill_date=cls.calculate_first_emi_date(product_order_date=loan.amortization_date),
Expand Down
1 change: 1 addition & 0 deletions src/rush/card/term_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def create(cls, session: Session, **kwargs) -> Loan:
loan.can_close_early = kwargs.get("can_close_early") or False
loan.tenure_in_months = kwargs.get("tenure")
loan.loan_status = "NOT STARTED"
loan.sub_product_type = "tenure_loan"
# Don't want to overwrite default value in case of None.
if kwargs.get("interest_free_period_in_days"):
loan.interest_free_period_in_days = kwargs.get("interest_free_period_in_days")
Expand Down
6 changes: 5 additions & 1 deletion src/rush/create_bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def bill_generate(
session.add(lt)
session.flush()

# Set product price as unbilled amount.
unbilled_balance = bill.get_unbilled_amount()
bill.table.gross_principal = unbilled_balance

bill_generate_event(session=session, bill=bill, user_loan=user_loan, event=lt)

bill.table.is_generated = True
Expand All @@ -99,7 +103,7 @@ def bill_generate(
session=session, book_string=f"{bill.id}/bill/principal_receivable/a"
)

# Update the bill row here.
# set net product price after reducing prepayment if any.
bill.table.principal = billed_amount

# Handling child loan emis for this bill.
Expand Down
2 changes: 2 additions & 0 deletions src/rush/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Loan(AuditMixin):
downpayment_percent: Decimal = Column(Numeric, nullable=True, default=Decimal(0))
can_close_early = Column(Boolean, nullable=True, default=True)
tenure_in_months = Column(Integer, nullable=True)
sub_product_type = Column(String(15), nullable=True)

__mapper_args__ = {
"polymorphic_identity": "v3_loans",
Expand Down Expand Up @@ -243,6 +244,7 @@ class LoanData(AuditMixin):
loan_id = Column(Integer, ForeignKey(Loan.id))
is_generated = Column(Boolean, nullable=False, server_default="false")
principal: Decimal = Column(Numeric, nullable=True)
gross_principal: Decimal = Column(Numeric, nullable=True)
principal_instalment: Decimal = Column(Numeric, nullable=True)
interest_to_charge: Decimal = Column(Numeric, nullable=True)

Expand Down
2 changes: 1 addition & 1 deletion src/rush/payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
_adjust_bill,
_adjust_for_prepayment,
adjust_for_revenue,
limit_assignment_event,
get_revenue_book_str_for_fee,
limit_assignment_event,
)
from rush.ledger_utils import (
create_ledger_entry_from_str,
Expand Down
2 changes: 0 additions & 2 deletions src/test/alembic_config/versions/4d3058ca5d21_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import sqlalchemy as sa
from alembic import op

from rush.models import Loan

# revision identifiers, used by Alembic.
revision = "4d3058ca5d21"
down_revision = "6a86ce49ea3f"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""net_product_price_sub_product_type
Revision ID: 9e3c39133b32
Revises: 4d3058ca5d21
Create Date: 2021-05-07 00:52:20.376074
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "9e3c39133b32"
down_revision = "4d3058ca5d21"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column("loan_data", sa.Column("gross_principal", sa.Numeric(), nullable=True))
op.add_column("v3_loans", sa.Column("sub_product_type", sa.String(15), nullable=True))


def downgrade() -> None:
pass
4 changes: 3 additions & 1 deletion src/test/test_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ def _generate_bill_2(session: Session) -> None:
txn_ref_no="dummy_txn_ref_no_10",
trace_no="123456",
)

assert user_loan.sub_product_type == "card"
_, user_loan_balance = get_account_balance_from_str(
session=session, book_string=f"{user_loan.loan_id}/card/available_limit/a"
)
Expand Down Expand Up @@ -3154,6 +3154,8 @@ def test_prepayment(session: Session) -> None:
# run_anomaly is reversing interest charged entry and adding it into prepayment amount.
# assert billed_amount == Decimal("30.67")
assert billed_amount == Decimal("0")
assert latest_bill.gross_principal == Decimal(1000)
assert latest_bill.principal == Decimal(0)


#
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_reset_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def test_reset_journal_entries_kv(session: Session) -> None:
user_id=6,
payment_request_id="reset_1",
)

assert loan.sub_product_type == "tenure_loan"
payment_date = parse_date("2018-11-14")
payment_request_id = "reset_1"
payment_requests_data = pay_payment_request(
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_term_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_create_term_loan(session: Session) -> None:
assert loan.get_remaining_min() == Decimal("0")

assert loan.get_remaining_max() == Decimal("7090")

assert loan.sub_product_type == "tenure_loan"
all_emis = user_loan.get_loan_schedule()

assert len(all_emis) == 12
Expand Down

0 comments on commit 9bc7956

Please sign in to comment.