test start
All checks were successful
cicd / ci (push) Successful in 1m28s

This commit is contained in:
bel
2024-07-14 08:42:31 -06:00
parent 682dc9880e
commit 3e001b8ddd
3 changed files with 149 additions and 41 deletions

View File

@@ -30,6 +30,42 @@ type transactionRecipient struct {
isSet bool
}
func (t transaction) deltas() Deltas {
result := []Delta{}
sums := map[string]float64{}
for _, recipient := range t.recipients {
sums[recipient.currency] += recipient.value
result = append(result, newDelta(
t.name,
t.date,
t.description,
recipient.name,
recipient.value,
recipient.currency,
recipient.isSet,
))
}
for currency, value := range sums {
if value == 0 {
continue
}
if t.payee == "" {
//return nil, fmt.Errorf("didnt find net zero and no dumping ground payee set: %+v", transaction)
} else {
result = append(result, newDelta(
t.name,
t.date,
t.description,
t.payee,
-1.0*value,
currency,
false,
))
}
}
return result
}
func (t transactionRecipient) empty() bool {
return t == (transactionRecipient{})
}