diff --git a/charging_tests/ddazmbl1_test.go b/charging_tests/ddazmbl1_test.go index fffcaa240..9f9669ab5 100644 --- a/charging_tests/ddazmbl1_test.go +++ b/charging_tests/ddazmbl1_test.go @@ -22,13 +22,13 @@ import ( "testing" "time" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/cache2go" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/scheduler" ) var ratingDb engine.RatingStorage -var acntDb engine.AccountingStorage +var acntDb engine.AccountingStorage func init() { ratingDb, _ = engine.NewMapStorageJson() @@ -37,7 +37,6 @@ func init() { engine.SetAccountingStorage(acntDb) } - func TestLoadCsvTp(t *testing.T) { timings := `ALWAYS,*any,*any,*any,*any,00:00:00 ASAP,*any,*any,*any,*any,*asap` @@ -130,14 +129,14 @@ func TestExecuteActions(t *testing.T) { func TestDebit(t *testing.T) { cd := &engine.CallDescriptor{ - Direction: "*out", - TOR: "call", - Tenant: "cgrates.org", - Subject: "12345", - Account: "12345", - Destination: "447956933443", - TimeStart: time.Date(2014, 3, 4, 6, 0, 0, 0, time.UTC), - TimeEnd: time.Date(2014, 3, 4, 6, 0, 10, 0, time.UTC), + Direction: "*out", + TOR: "call", + Tenant: "cgrates.org", + Subject: "12345", + Account: "12345", + Destination: "447956933443", + TimeStart: time.Date(2014, 3, 4, 6, 0, 0, 0, time.UTC), + TimeEnd: time.Date(2014, 3, 4, 6, 0, 10, 0, time.UTC), } if cc, err := cd.Debit(); err != nil { t.Error(err) @@ -148,7 +147,7 @@ func TestDebit(t *testing.T) { if err != nil { t.Error(err) } - if acnt.BalanceMap[engine.MINUTES+engine.OUTBOUND][0].Value != 39.8 { // How does the minutes should look like if we debit in seconds? + if acnt.BalanceMap[engine.MINUTES+engine.OUTBOUND][0].Value != 20 { t.Error("Account does not have expected minutes in balance", acnt.BalanceMap[engine.MINUTES+engine.OUTBOUND][0].Value) } if acnt.BalanceMap[engine.CREDIT+engine.OUTBOUND][0].Value != 9.99 { diff --git a/engine/account.go b/engine/account.go index 705e21ebe..1fb8e04d4 100644 --- a/engine/account.go +++ b/engine/account.go @@ -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 -} diff --git a/test.sh b/test.sh index 0789794ca..831b73e97 100755 --- a/test.sh +++ b/test.sh @@ -15,6 +15,8 @@ go test -i github.com/cgrates/cgrates/cdre go test github.com/cgrates/cgrates/engine en=$? +go test github.com/cgrates/cgrates/charging_tests +ct=$? go test github.com/cgrates/cgrates/sessionmanager sm=$? go test github.com/cgrates/cgrates/config @@ -39,4 +41,4 @@ go test github.com/cgrates/cgrates/cdre cdre=$? -exit $en && $sm && $cfg && $bl && $cr && $md && $cdrs && $cdrc && $fs && $ut && $hs && $c2g && $cdre +exit $en && $ct && $sm && $cfg && $bl && $cr && $md && $cdrs && $cdrc && $fs && $ut && $hs && $c2g && $cdre