fix for maxcost callcost information

This commit is contained in:
Radu Ioan Fericean
2015-05-26 13:50:54 +03:00
parent d97b996739
commit f4f56937b7
5 changed files with 38 additions and 4 deletions

View File

@@ -337,7 +337,7 @@ func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
if ts.Increments == nil {
ts.createIncrementsSlice()
}
//log.Printf("TS: %+v", ts)
if ts.RateInterval == nil {
Logger.Err(fmt.Sprintf("Nil RateInterval ERROR on TS: %+v, CC: %+v, from CD: %+v", ts, cc, cd))
return nil, errors.New("timespan with no rate interval assigned")
@@ -472,6 +472,8 @@ func (b *Balance) DebitMoney(cd *CallDescriptor, ub *Account, count bool, dryRun
if count {
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationIds: cc.Destination}})
}
//log.Printf("TS: %+v", cc.Cost)
// go to nextincrement
continue
}

View File

@@ -576,7 +576,7 @@ func (cd *CallDescriptor) debit(account *Account, dryRun bool, goNegative bool)
}
//log.Printf("Debit CD: %+v", cd)
cc, err = account.debitCreditBalance(cd, !dryRun, dryRun, goNegative)
//log.Print("HERE: ", cc, err)
//log.Printf("HERE: %+v %v", cc, err)
if err != nil {
Logger.Err(fmt.Sprintf("<Rater> Error getting cost for account key <%s>: %s", cd.GetAccountKey(), err.Error()))
return nil, err

View File

@@ -558,6 +558,29 @@ func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
}
}
func TestMaxDebitWithMaxCostFree(t *testing.T) {
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
cd := &CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "max",
Account: "max",
Destination: "0723123113",
TimeStart: time.Date(2015, 3, 23, 19, 0, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 3, 23, 19, 30, 0, 0, time.UTC),
MaxCostSoFar: 0,
}
cc, err := cd.MaxDebit()
expected := 10.0
if cc.Cost != expected || err != nil {
t.Errorf("Expected %v was %v", expected, cc.Cost)
}
}
func TestGetCostWithMaxCostFree(t *testing.T) {
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
for _, at := range ap {

View File

@@ -274,7 +274,16 @@ func (ts *TimeSpan) getCost() float64 {
ts.Cost = utils.Round(cost, ts.RateInterval.Rating.RoundingDecimals, ts.RateInterval.Rating.RoundingMethod)
return ts.Cost
} else {
return ts.Increments[0].Cost * float64(ts.Increments.Length())
cost := 0.0
// some increments may have 0 cost because of the max cost strategy
for _, inc := range ts.Increments {
cost += inc.Cost
}
if ts.RateInterval != nil && ts.RateInterval.Rating != nil {
return utils.Round(cost, ts.RateInterval.Rating.RoundingDecimals, ts.RateInterval.Rating.RoundingMethod)
} else {
return utils.Round(cost, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
}
}
}

View File

@@ -235,7 +235,7 @@ func TestTimespanGetCostIntervals(t *testing.T) {
ts.Increments[i] = &Increment{Cost: 0.02}
}
if ts.getCost() != 0.22 {
t.Error("Error caclulating timspan cost: ", ts.getCost())
t.Error("Error caclulating timespan cost: ", ts.getCost())
}
}