counterparty was a structured field only nlb could fill honestly. revolut and traderepublic invented one by running an IBAN-shaped regex over the description they had just built, and the two spellings disagreed -- SI56 1234 5678 9012 345 against SI56123456789012345 -- so a literal rule pattern that worked on one account silently matched nothing on another. It is gone from the model, the index, the rule keys, ls --wide and the rules screen. nlb now appends its IBAN column to the end of the description, where the other two already keep theirs, so match = "*SI56*" works everywhere. That changes those descriptions and with them their fingerprints, so a statement overlapping an already-imported period will re-add rather than dedupe those rows until the index is rebuilt. An index built by an older binary drops the column when it is opened. The index itself moves from .money/index.db up to index.db beside rules.toml. Nothing looks in the old location, so an existing one has to be moved by hand -- otherwise the tool quietly starts a fresh index and the manual tags in the old file, the only thing statements cannot reproduce, stay behind in it. The csv and cmd parsers are gone along with the [csv] and [cmd] config they carried. cmd shelled out to the Python extractors, which were ported to Go and deleted, so it bridged to nothing; csv was a generic column-mapped fallback that no account used, and between them they were the largest configuration surface in the tool. A bank is now described in Go, where it can be tested. The importer tests register their own three-column parser rather than borrow a bank's, so they stay about the directory walk, dedupe and per-file error reporting. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
// Package model holds the core domain types shared by every other package.
|
|
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Account is one folder in the data root.
|
|
type Account struct {
|
|
ID int64
|
|
Slug string // folder name, unique
|
|
Name string // human readable, from account.toml
|
|
Currency string
|
|
MinorDigits int
|
|
}
|
|
|
|
// Transaction is a single line extracted from a statement, plus whatever the
|
|
// rules engine and the user have said about it.
|
|
//
|
|
// Amount is stored in minor units (cents) and signed: negative is an outflow.
|
|
type Transaction struct {
|
|
ID int64
|
|
AccountID int64
|
|
AccountSlug string
|
|
Currency string
|
|
MinorDigits int
|
|
|
|
Fingerprint string
|
|
Date string // YYYY-MM-DD
|
|
Description string
|
|
AmountMinor int64
|
|
SourceFileID int64
|
|
SourcePath string
|
|
|
|
// Type is the bank's own classification, e.g. Revolut's CARD_PAYMENT.
|
|
Type string
|
|
// BalanceMinor is the running balance the statement reported after this
|
|
// transaction, when it reports one. Used to verify the balance chain.
|
|
BalanceMinor *int64
|
|
|
|
RuleTag string
|
|
ManualTag string
|
|
RuleTransfer bool
|
|
ManualTransfer *bool
|
|
}
|
|
|
|
// Tag is the effective category: a manual tag always beats a rule tag.
|
|
func (t Transaction) Tag() string {
|
|
if t.ManualTag != "" {
|
|
return t.ManualTag
|
|
}
|
|
return t.RuleTag
|
|
}
|
|
|
|
// IsTransfer reports whether this line moves money between the user's own
|
|
// accounts and so must not count as spending. A manual override wins.
|
|
func (t Transaction) IsTransfer() bool {
|
|
if t.ManualTransfer != nil {
|
|
return *t.ManualTransfer
|
|
}
|
|
return t.RuleTransfer
|
|
}
|
|
|
|
// FormatAmount renders the amount using the account's minor-unit scale.
|
|
func (t Transaction) FormatAmount() string {
|
|
return FormatMinor(t.AmountMinor, t.MinorDigits)
|
|
}
|
|
|
|
// FormatMinor renders minor units as a decimal string, e.g. -4520/2 -> "-45.20".
|
|
func FormatMinor(minor int64, digits int) string {
|
|
if digits <= 0 {
|
|
return fmt.Sprintf("%d", minor)
|
|
}
|
|
neg := minor < 0
|
|
if neg {
|
|
minor = -minor
|
|
}
|
|
scale := int64(1)
|
|
for i := 0; i < digits; i++ {
|
|
scale *= 10
|
|
}
|
|
whole, frac := minor/scale, minor%scale
|
|
s := fmt.Sprintf("%d.%0*d", whole, digits, frac)
|
|
if neg {
|
|
s = "-" + s
|
|
}
|
|
return s
|
|
}
|
|
|
|
// NormalizeDescription collapses whitespace and upper-cases, so that
|
|
// fingerprints and glob matching are insensitive to statement formatting noise.
|
|
func NormalizeDescription(s string) string {
|
|
return strings.ToUpper(strings.Join(strings.Fields(s), " "))
|
|
}
|