deltas try to remember filename, lineno

This commit is contained in:
Bel LaPointe
2025-04-03 11:54:29 -06:00
parent fb1ddc72c3
commit 1f9919a172
4 changed files with 47 additions and 9 deletions

View File

@@ -110,6 +110,9 @@ type transaction struct {
payee string
recipients []transactionRecipient
name string
fileName string
lineNo int
}
func (t transaction) empty() bool {
@@ -126,7 +129,7 @@ type transactionRecipient struct {
func (t transaction) deltas() Deltas {
result := []Delta{}
sums := map[string]float64{}
for _, recipient := range t.recipients {
for i, recipient := range t.recipients {
sums[recipient.currency] += recipient.value
result = append(result, newDelta(
t.name,
@@ -137,6 +140,8 @@ func (t transaction) deltas() Deltas {
recipient.value,
recipient.currency,
recipient.isSet,
t.fileName,
t.lineNo+i,
))
}
for currency, value := range sums {
@@ -155,6 +160,8 @@ func (t transaction) deltas() Deltas {
-1.0*value,
currency,
false,
t.fileName,
t.lineNo,
))
}
}
@@ -194,6 +201,8 @@ func (files Files) _transactions(file string) ([]transaction, error) {
name := fmt.Sprintf("%s/%d", file, len(result))
one, err := readTransaction(name, r)
if !one.empty() {
one.fileName = file
one.lineNo = len(result)
result = append(result, one)
}
if err == io.EOF {