.src.ledger.Delta.transaction = filename/idx
cicd / ci (push) Successful in 1m27s
Details
cicd / ci (push) Successful in 1m27s
Details
parent
bdcd9fe26a
commit
e633ee07ab
|
|
@ -15,9 +15,10 @@ type Delta struct {
|
||||||
Currency Currency
|
Currency Currency
|
||||||
Description string
|
Description string
|
||||||
isSet bool
|
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{
|
return Delta{
|
||||||
Date: d,
|
Date: d,
|
||||||
Name: name,
|
Name: name,
|
||||||
|
|
@ -25,6 +26,7 @@ func newDelta(d, desc, name string, v float64, c string, isSet bool) Delta {
|
||||||
Currency: Currency(c),
|
Currency: Currency(c),
|
||||||
Description: desc,
|
Description: desc,
|
||||||
isSet: isSet,
|
isSet: isSet,
|
||||||
|
transaction: transaction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,11 @@ import (
|
||||||
|
|
||||||
func TestDelta(t *testing.T) {
|
func TestDelta(t *testing.T) {
|
||||||
d := "2099-08-07"
|
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 {
|
if delta.Date != d {
|
||||||
t.Error(delta.Date)
|
t.Error(delta.Date)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,7 @@ func (files Files) Deltas(like ...Like) (Deltas, error) {
|
||||||
for _, recipient := range transaction.recipients {
|
for _, recipient := range transaction.recipients {
|
||||||
sums[recipient.currency] += recipient.value
|
sums[recipient.currency] += recipient.value
|
||||||
delta := newDelta(
|
delta := newDelta(
|
||||||
|
transaction.name,
|
||||||
transaction.date,
|
transaction.date,
|
||||||
transaction.description,
|
transaction.description,
|
||||||
recipient.name,
|
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)
|
//return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
|
||||||
} else {
|
} else {
|
||||||
delta := newDelta(
|
delta := newDelta(
|
||||||
|
transaction.name,
|
||||||
transaction.date,
|
transaction.date,
|
||||||
transaction.description,
|
transaction.description,
|
||||||
transaction.payee,
|
transaction.payee,
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,10 @@ func TestFileDeltas(t *testing.T) {
|
||||||
if i >= len(deltas) {
|
if i >= len(deltas) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if deltas[i].transaction == "" {
|
||||||
|
t.Error(deltas[i].transaction)
|
||||||
|
}
|
||||||
|
deltas[i].transaction = ""
|
||||||
if want[i] != deltas[i] {
|
if want[i] != deltas[i] {
|
||||||
t.Errorf("[%d] \n\twant=%s, \n\t got=%s", i, want[i].Debug(), deltas[i].Debug())
|
t.Errorf("[%d] \n\twant=%s, \n\t got=%s", i, want[i].Debug(), deltas[i].Debug())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ type transaction struct {
|
||||||
description string
|
description string
|
||||||
payee string
|
payee string
|
||||||
recipients []transactionRecipient
|
recipients []transactionRecipient
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t transaction) empty() bool {
|
func (t transaction) empty() bool {
|
||||||
|
|
@ -59,7 +60,8 @@ func (files Files) _transactions(file string) ([]transaction, error) {
|
||||||
|
|
||||||
result := make([]transaction, 0)
|
result := make([]transaction, 0)
|
||||||
for {
|
for {
|
||||||
one, err := readTransaction(r)
|
name := fmt.Sprintf("%s/%d", file, len(result))
|
||||||
|
one, err := readTransaction(name, r)
|
||||||
if !one.empty() {
|
if !one.empty() {
|
||||||
result = append(result, one)
|
result = append(result, one)
|
||||||
}
|
}
|
||||||
|
|
@ -72,8 +74,8 @@ func (files Files) _transactions(file string) ([]transaction, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readTransaction(r *bufio.Reader) (transaction, error) {
|
func readTransaction(name string, r *bufio.Reader) (transaction, error) {
|
||||||
result, err := _readTransaction(r)
|
result, err := _readTransaction(name, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +91,7 @@ func readTransaction(r *bufio.Reader) (transaction, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _readTransaction(r *bufio.Reader) (transaction, error) {
|
func _readTransaction(name string, r *bufio.Reader) (transaction, error) {
|
||||||
readTransactionLeadingWhitespace(r)
|
readTransactionLeadingWhitespace(r)
|
||||||
|
|
||||||
firstLine, err := readTransactionLine(r)
|
firstLine, err := readTransactionLine(r)
|
||||||
|
|
@ -107,6 +109,7 @@ func _readTransaction(r *bufio.Reader) (transaction, error) {
|
||||||
result := transaction{
|
result := transaction{
|
||||||
date: string(dateDescriptionMatches[0][1]),
|
date: string(dateDescriptionMatches[0][1]),
|
||||||
description: string(dateDescriptionMatches[0][2]),
|
description: string(dateDescriptionMatches[0][2]),
|
||||||
|
name: name,
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func TestReadTransaction(t *testing.T) {
|
||||||
c := d
|
c := d
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
r := bufio.NewReader(strings.NewReader(c.input))
|
r := bufio.NewReader(strings.NewReader(c.input))
|
||||||
got, err := readTransaction(r)
|
got, err := readTransaction("", r)
|
||||||
if err != c.err {
|
if err != c.err {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue