This commit is contained in:
@@ -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{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user