.src.ledger.Delta.transaction = filename/idx
cicd / ci (push) Successful in 1m27s Details

main
bel 2024-07-13 12:35:10 -06:00
parent bdcd9fe26a
commit e633ee07ab
6 changed files with 21 additions and 7 deletions

View File

@ -15,9 +15,10 @@ type Delta struct {
Currency Currency
Description string
isSet bool
transaction string
}
func newDelta(d, desc, name string, v float64, c string, isSet bool) Delta {
func newDelta(transaction string, d, desc, name string, v float64, c string, isSet bool) Delta {
return Delta{
Date: d,
Name: name,
@ -25,6 +26,7 @@ func newDelta(d, desc, name string, v float64, c string, isSet bool) Delta {
Currency: Currency(c),
Description: desc,
isSet: isSet,
transaction: transaction,
}
}

View File

@ -6,8 +6,11 @@ import (
func TestDelta(t *testing.T) {
d := "2099-08-07"
delta := newDelta(d, "", "name", 34.56, "$", false)
delta := newDelta("x", d, "", "name", 34.56, "$", false)
if delta.transaction != "x" {
t.Error(delta.transaction)
}
if delta.Date != d {
t.Error(delta.Date)
}

View File

@ -212,6 +212,7 @@ func (files Files) Deltas(like ...Like) (Deltas, error) {
for _, recipient := range transaction.recipients {
sums[recipient.currency] += recipient.value
delta := newDelta(
transaction.name,
transaction.date,
transaction.description,
recipient.name,
@ -229,6 +230,7 @@ func (files Files) Deltas(like ...Like) (Deltas, error) {
//return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
} else {
delta := newDelta(
transaction.name,
transaction.date,
transaction.description,
transaction.payee,

View File

@ -271,6 +271,10 @@ func TestFileDeltas(t *testing.T) {
if i >= len(deltas) {
break
}
if deltas[i].transaction == "" {
t.Error(deltas[i].transaction)
}
deltas[i].transaction = ""
if want[i] != deltas[i] {
t.Errorf("[%d] \n\twant=%s, \n\t got=%s", i, want[i].Debug(), deltas[i].Debug())
}

View File

@ -16,6 +16,7 @@ type transaction struct {
description string
payee string
recipients []transactionRecipient
name string
}
func (t transaction) empty() bool {
@ -59,7 +60,8 @@ func (files Files) _transactions(file string) ([]transaction, error) {
result := make([]transaction, 0)
for {
one, err := readTransaction(r)
name := fmt.Sprintf("%s/%d", file, len(result))
one, err := readTransaction(name, r)
if !one.empty() {
result = append(result, one)
}
@ -72,8 +74,8 @@ func (files Files) _transactions(file string) ([]transaction, error) {
}
}
func readTransaction(r *bufio.Reader) (transaction, error) {
result, err := _readTransaction(r)
func readTransaction(name string, r *bufio.Reader) (transaction, error) {
result, err := _readTransaction(name, r)
if err != nil {
return result, err
}
@ -89,7 +91,7 @@ func readTransaction(r *bufio.Reader) (transaction, error) {
return result, nil
}
func _readTransaction(r *bufio.Reader) (transaction, error) {
func _readTransaction(name string, r *bufio.Reader) (transaction, error) {
readTransactionLeadingWhitespace(r)
firstLine, err := readTransactionLine(r)
@ -107,6 +109,7 @@ func _readTransaction(r *bufio.Reader) (transaction, error) {
result := transaction{
date: string(dateDescriptionMatches[0][1]),
description: string(dateDescriptionMatches[0][2]),
name: name,
}
for {

View File

@ -55,7 +55,7 @@ func TestReadTransaction(t *testing.T) {
c := d
t.Run(name, func(t *testing.T) {
r := bufio.NewReader(strings.NewReader(c.input))
got, err := readTransaction(r)
got, err := readTransaction("", r)
if err != c.err {
t.Error(err)
}