This commit is contained in:
Bel LaPointe
2023-10-24 06:09:53 -06:00
parent ed75a59ca0
commit 459bc54760
2 changed files with 81 additions and 2 deletions

View File

@@ -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 {