diff --git a/engine/account_test.go b/engine/account_test.go index 27dca9925..b48a0750c 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -1703,6 +1703,7 @@ func TestDebitGeneric(t *testing.T) { func TestDebitGenericBalance(t *testing.T) { cc := &CallCost{ + Category: "call", Destination: "0723045326", Timespans: []*TimeSpan{ { @@ -1722,6 +1723,7 @@ func TestDebitGenericBalance(t *testing.T) { ToR: utils.MetaVoice, } cd := &CallDescriptor{ + Category: "call", TimeStart: cc.Timespans[0].TimeStart, TimeEnd: cc.Timespans[0].TimeEnd, Destination: cc.Destination, @@ -1734,7 +1736,7 @@ func TestDebitGenericBalance(t *testing.T) { utils.MetaGeneric: { &Balance{Uuid: "testm", Value: 100, Weight: 5, DestinationIDs: utils.StringMap{"NAT": true}, - Factor: ValueFactor{utils.MetaVoice: 60 * float64(time.Second)}}}, + Factor: ValueFactor{"call": 60 * float64(time.Second)}}}, utils.MetaMonetary: {&Balance{Value: 21}}, }} var err error @@ -1756,6 +1758,7 @@ func TestDebitGenericBalance(t *testing.T) { func TestDebitGenericBalanceWithRatingSubject(t *testing.T) { cc := &CallCost{ + Category: "call", Destination: "0723045326", Timespans: []*TimeSpan{ { @@ -1774,6 +1777,7 @@ func TestDebitGenericBalanceWithRatingSubject(t *testing.T) { ToR: utils.MetaVoice, } cd := &CallDescriptor{ + Category: "call", TimeStart: cc.Timespans[0].TimeStart, TimeEnd: cc.Timespans[0].TimeEnd, Destination: cc.Destination, @@ -1786,7 +1790,7 @@ func TestDebitGenericBalanceWithRatingSubject(t *testing.T) { utils.MetaGeneric: { &Balance{Uuid: "testm", Value: 100, Weight: 5, DestinationIDs: utils.StringMap{"NAT": true}, - Factor: ValueFactor{utils.MetaVoice: 60 * float64(time.Second)}, + Factor: ValueFactor{"call": 60 * float64(time.Second)}, RatingSubject: "free"}}, utils.MetaMonetary: {&Balance{Value: 21}}, }} diff --git a/engine/balances.go b/engine/balances.go index cc983d3e0..0428ee87b 100644 --- a/engine/balances.go +++ b/engine/balances.go @@ -770,8 +770,8 @@ func (bc Balances) SaveDirtyBalances(acc *Account, initBal map[string]float64) { type ValueFactor map[string]float64 -func (f ValueFactor) GetValue(tor string) float64 { - if value, ok := f[tor]; ok { +func (f ValueFactor) GetValue(category string) float64 { + if value, ok := f[category]; ok { return value } return 1.0 @@ -876,7 +876,7 @@ func (b *Balance) debit(cd *CallDescriptor, ub *Account, moneyBalances Balances, //log.Printf("INCREMENET: %+v", inc) amount := float64(inc.Duration) if b.Factor != nil { - amount = utils.Round(amount/b.Factor.GetValue(tor), + amount = utils.Round(amount/b.Factor.GetValue(cd.Category), globalRoundingDecimals, utils.MetaRoundingUp) } if b.GetValue() >= amount { @@ -887,7 +887,8 @@ func (b *Balance) debit(cd *CallDescriptor, ub *Account, moneyBalances Balances, Value: b.Value, DestinationID: cc.Destination, Consumed: amount, - ToR: tor, //aici + Category: cd.Category, + ToR: tor, RateInterval: nil, } inc.BalanceInfo.AccountID = ub.ID @@ -1019,7 +1020,7 @@ func (b *Balance) debit(cd *CallDescriptor, ub *Account, moneyBalances Balances, var moneyBal *Balance if isUnitBal { if b.Factor != nil { - amount = utils.Round(amount/b.Factor.GetValue(cd.ToR), globalRoundingDecimals, utils.MetaRoundingUp) + amount = utils.Round(amount/b.Factor.GetValue(cd.Category), globalRoundingDecimals, utils.MetaRoundingUp) } for _, mb := range moneyBalances { if mb.GetValue() >= cost { @@ -1056,6 +1057,7 @@ func (b *Balance) debit(cd *CallDescriptor, ub *Account, moneyBalances Balances, Value: b.Value, DestinationID: cc.Destination, Consumed: amount, + Category: cc.Category, ToR: cc.ToR, RateInterval: ts.RateInterval, } diff --git a/engine/timespans.go b/engine/timespans.go index ee9e85f6b..e25b10526 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -108,6 +108,7 @@ type UnitInfo struct { Value float64 DestinationID string Consumed float64 + Category string ToR string RateInterval *RateInterval } @@ -128,6 +129,7 @@ func (ui *UnitInfo) Equal(other *UnitInfo) bool { ui.DestinationID == other.DestinationID && ui.Consumed == other.Consumed && ui.ToR == other.ToR && + ui.Category == other.Category && reflect.DeepEqual(ui.RateInterval, other.RateInterval) }