Skip to content

Commit

Permalink
issue #104 - switch account APR lookups to .effective_apr property, f…
Browse files Browse the repository at this point in the history
…or prime_rate_margin calculation
  • Loading branch information
jantman committed Aug 20, 2017
1 parent 9d4f4c5 commit c01e580
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Expand Up @@ -26,6 +26,14 @@ def upgrade():
nullable=True
)
)
op.add_column(
'accounts',
sa.Column(
'prime_rate_margin',
sa.Numeric(precision=5, scale=4),
nullable=True
)
)
op.add_column(
'accounts',
sa.Column(
Expand All @@ -47,4 +55,5 @@ def upgrade():
def downgrade():
op.drop_column('accounts', 'min_payment_class_name')
op.drop_column('accounts', 'interest_class_name')
op.drop_column('accounts', 'prime_rate_margin')
op.drop_column('accounts', 'apr')
8 changes: 8 additions & 0 deletions biweeklybudget/flaskapp/templates/account.html
Expand Up @@ -40,6 +40,14 @@
<th>APR</th>
<td>{{ acct.apr|decimal_to_percent }}%</td>
</tr>
<tr>
<th>Prime Rate Margin</th>
<td>{{ acct.prime_rate_margin|decimal_to_percent }}</td>
</tr>
<tr>
<th>Effective APR (calculated)</th>
<td>{{ acct.effective_apr|decimal_to_percent</td>
</tr>
<tr>
<th>Interest Class</th>
<td>{{ acct.interest_class_name }}</td>
Expand Down
2 changes: 1 addition & 1 deletion biweeklybudget/interest.py
Expand Up @@ -110,7 +110,7 @@ def _make_statements(self, accounts):
icharge = acct.latest_ofx_interest_charge
istmt = icharge.first_statement_by_date
icls = INTEREST_CALCULATION_NAMES[acct.interest_class_name]['cls'](
acct.apr
acct.effective_apr
)
bill_period = _BillingPeriod(icharge.date_posted.date())
min_pay_cls = MIN_PAYMENT_FORMULA_NAMES[
Expand Down
15 changes: 15 additions & 0 deletions biweeklybudget/models/account.py
Expand Up @@ -115,6 +115,9 @@ class Account(Base, ModelAsDict):
#: Finance rate (APR) for credit accounts
apr = Column(Numeric(precision=5, scale=4))

#: Margin added to the US Prime Rate to determine APR, for credit accounts
prime_rate_margin = Column(Numeric(precision=5, scale=4))

#: Name of the :py:class:`biweeklybudget.interest._InterestCalculation`
#: subclass used to calculate interest for this account.
interest_class_name = Column(String(70))
Expand Down Expand Up @@ -310,3 +313,15 @@ def latest_ofx_interest_charge(self):
logger.debug('Latest OFX Interest Charge for account %s: %s',
self, t)
return t

@property
def effective_apr(self):
"""
Return the effective APR for a credit account. If
:py:attr:`~.prime_rate_margin` is not Null, return it. Otherwise, return
:py:attr:`~.apr`.
:return: Effective account APR
:rtype: decimal.Decimal
"""
return self.apr

0 comments on commit c01e580

Please sign in to comment.