Changed the code to use the currency_affinity value
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package expenses
|
||||
|
||||
import (
|
||||
"expenses/config"
|
||||
mod "expenses/expenses/models"
|
||||
|
||||
dec "github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
@@ -48,6 +50,9 @@ func ParseFormShares(userIDs []string, shares []string, sharesIDs []string,
|
||||
// NormalizeShares will take the total of an expense and the proposed shares
|
||||
// and calculate how much each user actually has to pay - avoids fracd cents
|
||||
func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
|
||||
cfg := config.GetInstance()
|
||||
affi := cfg.CurrencyAffinity
|
||||
|
||||
excess := dec.NewFromFloat(0.0)
|
||||
ownerShIdx := -1
|
||||
for k := range e.Shares {
|
||||
@@ -55,9 +60,9 @@ func (a *ExpensesApp) NormalizeShares(e *mod.Expense) error {
|
||||
ownerShIdx = k
|
||||
}
|
||||
owed := e.Value.Mul(e.Shares[k].Share)
|
||||
excess = excess.Add(owed.Sub(owed.Truncate(2)))
|
||||
excess = excess.Add(owed.Sub(owed.Truncate(affi)))
|
||||
|
||||
e.Shares[k].Calculated = owed.Truncate(2)
|
||||
e.Shares[k].Calculated = owed.Truncate(affi)
|
||||
}
|
||||
|
||||
// It fails here for some reason
|
||||
|
||||
Reference in New Issue
Block a user