LoanStatus

bizlogic.loan.status.LoanStatus

Loan Status.

Source code in bizlogic/loan/status.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class LoanStatus():
    """Loan Status."""

    @staticmethod
    def loan_status(loan: Loan) -> LoanStatusType:
        """Get the status of a loan.

        Args:
            loan: the loan

        Returns:
            LoanStatusType: the status of the loan
        """
        now = datetime.now(timezone.utc)

        # if the loan has no transaction, it is a draft
        # TODO: check if transaction is valid
        if 'transaction' not in loan.keys():
            return LoanStatusType.DRAFT

        # if the loan has not expired and is not accepted
        elif loan['offer_expiry'] > now and not loan['accepted']:
            return LoanStatusType.PENDING_ACCEPTANCE

        # if the loan has expired and is not accepted
        elif loan['offer_expiry'] <= now and not loan['accepted']:
            return LoanStatusType.EXPIRED_UNACCEPTED

        # if the loan is accepted, regardless of expiry
        elif loan['accepted']:
            return LoanStatusType.ACCEPTED

        raise ValueError("Unable to determine loan status")

loan_status(loan) staticmethod

Get the status of a loan.

Parameters:
  • loan (Loan) –

    the loan

Returns:
  • LoanStatusType( LoanStatusType ) –

    the status of the loan

bizlogic/loan/status.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@staticmethod
def loan_status(loan: Loan) -> LoanStatusType:
    """Get the status of a loan.

    Args:
        loan: the loan

    Returns:
        LoanStatusType: the status of the loan
    """
    now = datetime.now(timezone.utc)

    # if the loan has no transaction, it is a draft
    # TODO: check if transaction is valid
    if 'transaction' not in loan.keys():
        return LoanStatusType.DRAFT

    # if the loan has not expired and is not accepted
    elif loan['offer_expiry'] > now and not loan['accepted']:
        return LoanStatusType.PENDING_ACCEPTANCE

    # if the loan has expired and is not accepted
    elif loan['offer_expiry'] <= now and not loan['accepted']:
        return LoanStatusType.EXPIRED_UNACCEPTED

    # if the loan is accepted, regardless of expiry
    elif loan['accepted']:
        return LoanStatusType.ACCEPTED

    raise ValueError("Unable to determine loan status")