Skip to content

Commit

Permalink
fix drop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobetic committed Mar 16, 2024
1 parent 261f6b3 commit f27691f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
8 changes: 7 additions & 1 deletion cmd/csv2coin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func readTransactions(in io.Reader, src *Source, rules *Rules) (transactions []*
break
}
check.NoError(err, "reading transaction")
transactions = append(transactions, transactionFrom(rec, src.fields, rules))
if nt := transactionFrom(rec, src.fields, rules); nt != nil {
transactions = append(transactions, nt)
}
}
return transactions
}
Expand All @@ -122,6 +124,10 @@ func transactionFrom(row []string, fields map[string]Fields, allRules *Rules) *c
toAccount := coin.Unbalanced
var notes []string
if rule := rules.RuleFor(description); rule != nil {
if rule.Account == nil {
// drop transaction
return nil
}
toAccount = rule.Account
notes = rule.Notes
}
Expand Down
15 changes: 8 additions & 7 deletions cmd/ofx2coin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ func readTransactions(r io.Reader, rules *coin.RuleIndex) (transactions []*coin.
if i == last {
balance = &(resp.BalAmt.Rat)
}
transactions = append(transactions,
newTransaction(rules,
t.DtPosted.Time,
trim(t.Name.String()+t.Memo.String()),
t.TrnAmt.Rat,
balance,
))
if nt := newTransaction(rules,
t.DtPosted.Time,
trim(t.Name.String()+t.Memo.String()),
t.TrnAmt.Rat,
balance,
); nt != nil {
transactions = append(transactions, nt)
}
}
}
// read credit card transactions
Expand Down
14 changes: 5 additions & 9 deletions cmd/ofx2coin/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ func Test_ReadTransactions(t *testing.T) {
if drop.Account != nil {
t.Error("should be nil")
}
assert.True(t, drop.Match([]byte("TO BE IGNORED WHEN WHATEVER")))
assert.True(t, drop.Match([]byte("TO BE IGNORED WHEN WATSWR")))
assert.Equal(t, len(drop.Notes), 1)
assert.Equal(t, drop.Notes[0], "payee with WHATEVER in it will be ignored")
assert.Equal(t, drop.Notes[0], "payee with WATSWR in it will be ignored")

r = strings.NewReader(txsSample)
r = newBMOReader(r)
txs, err := readTransactions(r, rules)
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, len(txs), 10)
assert.Equal(t, len(txs), 9)
for i, tx := range []string{
`2019/01/04 [CK]NO.272
Unbalanced 704.00 CAD
Expand All @@ -100,10 +100,6 @@ func Test_ReadTransactions(t *testing.T) {
`2019/01/14 [CW]HYDRO
Unbalanced 66.40 CAD
Assets:Bank:Checking -66.40 CAD
`,
`2019/01/14 [CW]WATSWR
Unbalanced 106.30 CAD
Assets:Bank:Checking -106.30 CAD
`,
`2019/01/15 [DN]ACME PAY
Assets:Bank:Checking 1211.04 CAD
Expand All @@ -130,8 +126,8 @@ var sample = `
common
Expenses:Groceries FRESHCO|COSTCO WHOLESALE|FARM BOY|LOBLAWS
Expenses:Auto:Gas COSTCO GAS|PETROCAN|SHELL
-- WHATEVER
; payee with WHATEVER in it will be ignored
-- WATSWR
; payee with WATSWR in it will be ignored
389249328477983 Assets:Bank:Savings
Income:Interest Interest
392843029797099 Assets:Bank:Checking
Expand Down

0 comments on commit f27691f

Please sign in to comment.