Remove the transfer flag
A transfer was a second verdict carried alongside the tag: a boolean set by transfer = true in a rule or by x in the TUI, kept in its own pair of rule_ and manual_ columns, whose one real effect was to hold the row out of the report. The rest of it was display -- a T column in the transaction list, in the rules screen and in money ls. Money moved between your own accounts is now tagged like anything else and counts like anything else. The leg leaving checking is an outflow and the leg arriving in savings is an inflow, so a report over the whole data root roughly nets out while one scoped to a single account or month does not. That is the price of one verdict per transaction instead of two. A rule now needs a tag, and one that set only transfer = true is refused by number on load. A leftover transfer key beside a tag is ignored, as unknown TOML keys always were, and an index built by an older binary drops both columns when it is opened. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,13 +128,13 @@ func TestFirstMatchWins(t *testing.T) {
|
||||
{Match: "*LIDL EXPRESS*", Tag: "snacks"},
|
||||
{Match: "*LIDL*", Tag: "groceries"},
|
||||
}})
|
||||
if tag, _ := engine.Apply("checking", "CARD LIDL EXPRESS 12"); tag != "snacks" {
|
||||
if tag := engine.Apply("checking", "CARD LIDL EXPRESS 12"); tag != "snacks" {
|
||||
t.Errorf("tag = %q, want snacks (earlier rule must win)", tag)
|
||||
}
|
||||
if tag, _ := engine.Apply("checking", "CARD LIDL 12"); tag != "groceries" {
|
||||
if tag := engine.Apply("checking", "CARD LIDL 12"); tag != "groceries" {
|
||||
t.Errorf("tag = %q, want groceries", tag)
|
||||
}
|
||||
if tag, _ := engine.Apply("checking", "SOMETHING ELSE"); tag != "" {
|
||||
if tag := engine.Apply("checking", "SOMETHING ELSE"); tag != "" {
|
||||
t.Errorf("tag = %q, want empty for an unmatched description", tag)
|
||||
}
|
||||
}
|
||||
@@ -187,17 +187,15 @@ func TestMatchIndex(t *testing.T) {
|
||||
|
||||
func TestAccountScopedRule(t *testing.T) {
|
||||
engine := New(&config.Rules{Rule: []config.Rule{
|
||||
{Match: "*TRANSFER*", Tag: "transfer", Transfer: true, Account: "savings"},
|
||||
{Match: "*TRANSFER*", Tag: "transfer", Account: "savings"},
|
||||
{Match: "*TRANSFER*", Tag: "misc"},
|
||||
}})
|
||||
|
||||
tag, transfer := engine.Apply("savings", "TRANSFER FROM CHECKING")
|
||||
if tag != "transfer" || !transfer {
|
||||
t.Errorf("savings: tag=%q transfer=%v, want transfer/true", tag, transfer)
|
||||
if tag := engine.Apply("savings", "TRANSFER FROM CHECKING"); tag != "transfer" {
|
||||
t.Errorf("savings: tag = %q, want transfer", tag)
|
||||
}
|
||||
tag, transfer = engine.Apply("checking", "TRANSFER FROM CHECKING")
|
||||
if tag != "misc" || transfer {
|
||||
t.Errorf("checking: tag=%q transfer=%v, want misc/false", tag, transfer)
|
||||
if tag := engine.Apply("checking", "TRANSFER FROM CHECKING"); tag != "misc" {
|
||||
t.Errorf("checking: tag = %q, want misc", tag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,13 +208,13 @@ func TestTypeRules(t *testing.T) {
|
||||
}})
|
||||
|
||||
// A rule setting several patterns requires all of them to match.
|
||||
tag, _ := engine.ApplyTxn("checking", model.Transaction{
|
||||
tag := engine.ApplyTxn("checking", model.Transaction{
|
||||
Description: "LIDL SOFIA", Type: "CARD_PAYMENT",
|
||||
})
|
||||
if tag != "groceries" {
|
||||
t.Errorf("tag = %q, want groceries", tag)
|
||||
}
|
||||
tag, _ = engine.ApplyTxn("checking", model.Transaction{
|
||||
tag = engine.ApplyTxn("checking", model.Transaction{
|
||||
Description: "LIDL SOFIA", Type: "TRANSFER",
|
||||
})
|
||||
if tag != "" {
|
||||
@@ -224,68 +222,9 @@ func TestTypeRules(t *testing.T) {
|
||||
}
|
||||
|
||||
// Type alone works too.
|
||||
if tag, _ := engine.ApplyTxn("checking", model.Transaction{
|
||||
if tag := engine.ApplyTxn("checking", model.Transaction{
|
||||
Description: "WITHDRAWAL", Type: "ATM",
|
||||
}); tag != "cash" {
|
||||
t.Errorf("tag = %q, want cash", tag)
|
||||
}
|
||||
}
|
||||
|
||||
// Transfers can also be overridden by hand, independently of the tag.
|
||||
func TestManualTransferOverride(t *testing.T) {
|
||||
db := testDB(t)
|
||||
seed(t, db, "TRANSFER TO SAVINGS")
|
||||
|
||||
engine := New(&config.Rules{Rule: []config.Rule{
|
||||
{Match: "*TO SAVINGS*", Tag: "transfer", Transfer: true},
|
||||
}})
|
||||
if _, err := engine.Retag(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
txn := byDescription(t, db, "TRANSFER TO SAVINGS")
|
||||
if !txn.IsTransfer() {
|
||||
t.Fatal("expected the rule to mark this as a transfer")
|
||||
}
|
||||
|
||||
no := false
|
||||
if err := db.SetManualTransfer(txn.ID, &no); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.Retag(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if byDescription(t, db, "TRANSFER TO SAVINGS").IsTransfer() {
|
||||
t.Error("manual transfer override was lost on retag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUntaggedFilter(t *testing.T) {
|
||||
db := testDB(t)
|
||||
seed(t, db, "LIDL SOFIA", "SOME RANDOM SHOP")
|
||||
|
||||
engine := New(&config.Rules{Rule: []config.Rule{{Match: "*LIDL*", Tag: "groceries"}}})
|
||||
if _, err := engine.Retag(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
untagged, err := db.Transactions(store.Filter{Untagged: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(untagged) != 1 || untagged[0].Description != "SOME RANDOM SHOP" {
|
||||
t.Fatalf("untagged = %+v, want only SOME RANDOM SHOP", untagged)
|
||||
}
|
||||
|
||||
// A manual tag must remove the row from the untagged view.
|
||||
if err := db.SetManualTag(untagged[0].ID, "hobby"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
untagged, err = db.Transactions(store.Filter{Untagged: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(untagged) != 0 {
|
||||
t.Errorf("untagged = %+v, want none", untagged)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user