Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Fixed bug in expense contribution calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotcourant committed May 23, 2021
1 parent 1113519 commit 8390fc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 21 additions & 0 deletions pkg/controller/fixtures/simple.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- model: Login
rows:
- _id: doug
email: doug.dimmadome@testing.monetr.app
password_hash: ""
first_name: Doug
last_name: Dimmadome
is_enabled: true
is_email_verified: true
is_phone_verified: false
- model: Account
rows:
- _id: doug
timezone: America/Chicago
- model: User
rows:
- _id: doug
account_id: "{{ $.Account.doug.account_id }}"
login_id: "{{ $.Login.doug.login_id }}"


11 changes: 2 additions & 9 deletions pkg/models/spending.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,10 @@ func (e *Spending) CalculateNextContribution(
e.IsBehind = false
}

// If the next time we would contribute to this expense is not behind and has more than one contribution to meet its
// target then we need to calculate a partial contribution.
numberOfContributions := 0
if nextContributionDate.Before(nextDueDate) {
numberOfContributions++
}

// TODO Handle expenses that recur more frequently than they are funded.
nowInTimezone := time.Now().In(timezone)
nextContributionRule.DTStart(nowInTimezone)
numberOfContributions = len(nextContributionRule.Between(nowInTimezone, nextDueDate, false))
nextContributionRule.DTStart(nextContributionDate)
numberOfContributions := len(nextContributionRule.Between(nowInTimezone, nextDueDate, false))

totalNeeded := e.TargetAmount - progressAmount
perContribution := totalNeeded / int64(numberOfContributions)
Expand Down

0 comments on commit 8390fc8

Please sign in to comment.