clean all balance precision, bugfix (thanks DigiDaz)

This commit is contained in:
Radu Ioan Fericean
2014-04-06 23:48:55 +03:00
parent d5a8a2c292
commit 2e6ee328c9
3 changed files with 38 additions and 33 deletions

View File

@@ -183,9 +183,33 @@ func (ub *Account) getBalancesForPrefix(prefix string, balances BalanceChain, sh
}
// resort by precision
usefulBalances.Sort()
// clear precision
for _, b := range usefulBalances {
b.precision = 0
}
return usefulBalances
}
// like getBalancesForPrefix but expanding shared balances
func (account *Account) getAlldBalancesForPrefix(destination, balanceType string) (bc BalanceChain) {
balances := account.getBalancesForPrefix(destination, account.BalanceMap[balanceType], "")
for _, b := range balances {
if b.SharedGroup != "" {
sharedGroup, err := accountingStorage.GetSharedGroup(b.SharedGroup, false)
if err != nil {
Logger.Warning(fmt.Sprintf("Could not get shared group: %v", b.SharedGroup))
continue
}
sharedBalances := sharedGroup.GetBalances(destination, balanceType, account)
sharedBalances = sharedGroup.SortBalancesByStrategy(b, sharedBalances)
bc = append(bc, sharedBalances...)
} else {
bc = append(bc, b)
}
}
return
}
func (ub *Account) debitCreditBalance(cc *CallCost, count bool) (err error) {
usefulMinuteBalances := ub.getAlldBalancesForPrefix(cc.Destination, MINUTES+cc.Direction)
usefulMoneyBalances := ub.getAlldBalancesForPrefix(cc.Destination, CREDIT+cc.Direction)
@@ -483,23 +507,3 @@ func (account *Account) GetUniqueSharedGroupMembers(destination, direction strin
}
return memberIds, nil
}
// like getBalancesForPrefix but expanding shared balances
func (account *Account) getAlldBalancesForPrefix(destination, balanceType string) (bc BalanceChain) {
balances := account.getBalancesForPrefix(destination, account.BalanceMap[balanceType], "")
for _, b := range balances {
if b.SharedGroup != "" {
sharedGroup, err := accountingStorage.GetSharedGroup(b.SharedGroup, false)
if err != nil {
Logger.Warning(fmt.Sprintf("Could not get shared group: %v", b.SharedGroup))
continue
}
sharedBalances := sharedGroup.GetBalances(destination, balanceType, account)
sharedBalances = sharedGroup.SortBalancesByStrategy(b, sharedBalances)
bc = append(bc, sharedBalances...)
} else {
bc = append(bc, b)
}
}
return
}