mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -1377,15 +1377,20 @@ func TestDebitDataUnits(t *testing.T) {
|
||||
}}
|
||||
var err error
|
||||
cc, err = rifsBalance.debitCreditBalance(cd, false, false, true)
|
||||
// test rating information
|
||||
ts := cc.Timespans[0]
|
||||
if ts.MatchedSubject != "testm" || ts.MatchedPrefix != "0723" || ts.MatchedDestId != "NAT" || ts.RatingPlanId != utils.META_NONE {
|
||||
t.Errorf("Error setting rating info: %+v", ts.ratingInfo)
|
||||
}
|
||||
if err != nil {
|
||||
t.Error("Error debiting balance: ", err)
|
||||
}
|
||||
if cc.Timespans[0].Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
if ts.Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", ts.Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value != 20 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
t.Log(cc.Timespans[0].Increments)
|
||||
t.Log(ts.Increments)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -184,6 +185,26 @@ func (b *Balance) Clone() *Balance {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Balance) getMatchingPrefixAndDestId(dest string) (prefix, destId string) {
|
||||
if b.DestinationIds != "" && b.DestinationIds != utils.ANY {
|
||||
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[interface{}]struct{})
|
||||
for dId, _ := range destIds {
|
||||
balDestIds := strings.Split(b.DestinationIds, utils.INFIELD_SEP)
|
||||
for _, balDestID := range balDestIds {
|
||||
if dId == balDestID {
|
||||
return p, balDestID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Returns the available number of seconds for a specified credit
|
||||
func (b *Balance) GetMinutesForCredit(origCD *CallDescriptor, initialCredit float64) (duration time.Duration, credit float64) {
|
||||
cd := origCD.Clone()
|
||||
@@ -292,6 +313,13 @@ func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
},
|
||||
},
|
||||
}
|
||||
prefix, destid := b.getMatchingPrefixAndDestId(cd.Destination)
|
||||
ts.setRatingInfo(&RatingInfo{
|
||||
MatchedSubject: b.Uuid,
|
||||
MatchedPrefix: prefix,
|
||||
MatchedDestId: destid,
|
||||
RatingPlanId: utils.META_NONE,
|
||||
})
|
||||
ts.createIncrementsSlice()
|
||||
//log.Printf("CC: %+v", ts)
|
||||
for incIndex, inc := range ts.Increments {
|
||||
|
||||
Reference in New Issue
Block a user