tdd whee
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package ledger
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
@@ -36,6 +38,12 @@ func (file File) Deltas(like ...Like) ([]Delta, error) {
|
||||
}
|
||||
}
|
||||
for currency, value := range sums {
|
||||
if value == 0 {
|
||||
continue
|
||||
}
|
||||
if transaction.payee == "" {
|
||||
return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
|
||||
}
|
||||
delta := newDelta(
|
||||
transaction.date,
|
||||
transaction.description,
|
||||
@@ -64,6 +72,10 @@ type transactionRecipient struct {
|
||||
currency string
|
||||
}
|
||||
|
||||
func (t transaction) empty() bool {
|
||||
return fmt.Sprint(t) == fmt.Sprint(transaction{})
|
||||
}
|
||||
|
||||
func (file File) transactions() ([]transaction, error) {
|
||||
f, err := os.Open(string(file))
|
||||
if err != nil {
|
||||
@@ -74,8 +86,10 @@ func (file File) transactions() ([]transaction, error) {
|
||||
result := make([]transaction, 0)
|
||||
for {
|
||||
one, err := readTransaction(f)
|
||||
result = append(result, one)
|
||||
if err == io.EOF {
|
||||
if !one.empty() {
|
||||
result = append(result, one)
|
||||
}
|
||||
if errors.Is(err, io.EOF) {
|
||||
return result, nil
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user