mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
better rate subject monet debit
This commit is contained in:
@@ -277,7 +277,7 @@ func (b *Balance) DebitMoney(cc *CallCost, count bool, ub *UserBalance) error {
|
||||
for _, nts := range newCC.Timespans {
|
||||
nts.createIncrementsSlice()
|
||||
paidTs = append(paidTs, nts)
|
||||
for nIdx, nInc := range nts.Increments {
|
||||
for _, nInc := range nts.Increments {
|
||||
// debit money
|
||||
amount := nInc.Cost
|
||||
if b.Value >= amount {
|
||||
@@ -288,7 +288,8 @@ func (b *Balance) DebitMoney(cc *CallCost, count bool, ub *UserBalance) error {
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: newCC.Direction, Balance: &Balance{Value: amount, DestinationId: newCC.Destination}})
|
||||
}
|
||||
} else {
|
||||
nts.SplitByIncrement(nIdx)
|
||||
increment.paid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,6 @@ func (ub *UserBalance) debitCreditBalance(cc *CallCost, count bool) error {
|
||||
for _, balance := range usefulMinuteBalances {
|
||||
balance.DebitMinutes(cc, count, ub, usefulMoneyBalances)
|
||||
}
|
||||
|
||||
allPaidWithMinutes := true
|
||||
for tsIndex := 0; tsIndex < len(cc.Timespans); tsIndex++ {
|
||||
ts := cc.Timespans[tsIndex]
|
||||
|
||||
@@ -694,7 +694,6 @@ func TestDebitCreditSubjectMixed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestDebitCreditSubjectMixedMoreTS(t *testing.T) {
|
||||
b1 := &Balance{Uuid: "testb", Value: 70, Weight: 10, DestinationId: "NAT", RateSubject: "minu"}
|
||||
cc := &CallCost{
|
||||
@@ -722,23 +721,27 @@ func TestDebitCreditSubjectMixedMoreTS(t *testing.T) {
|
||||
CREDIT + OUTBOUND: BalanceChain{&Balance{Uuid: "moneya", Value: 50, RateSubject: "minu"}},
|
||||
}}
|
||||
err := rifsBalance.debitCreditBalance(cc, false)
|
||||
if err != nil {
|
||||
t.Error("Error debiting balance: ", err)
|
||||
if err == nil {
|
||||
t.Error("Error showing debiting balance error: ", err)
|
||||
}
|
||||
t.Errorf("%+v %+v", cc.Timespans[0], cc.Timespans[1])
|
||||
//t.Logf("%+v %+v", cc.Timespans[0], cc.Timespans[1])
|
||||
if cc.Timespans[0].Increments[0].BalanceUuids[0] != "testb" ||
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Second {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 10 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 30 {
|
||||
if rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value != 20 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[CREDIT+OUTBOUND][1].Value != -30 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[MINUTES+OUTBOUND][0].Value, rifsBalance.BalanceMap[CREDIT+OUTBOUND][0].Value)
|
||||
}
|
||||
if len(cc.Timespans) != 2 || cc.Timespans[0].GetDuration() != time.Minute || cc.Timespans[1].GetDuration() != 20*time.Second {
|
||||
t.Error("Error truncating extra timespans: ", cc.Timespans)
|
||||
if len(cc.Timespans) != 2 || cc.Timespans[0].GetDuration() != 50*time.Second || cc.Timespans[1].GetDuration() != 30*time.Second {
|
||||
for _, ts := range cc.Timespans {
|
||||
t.Log(ts.GetDuration())
|
||||
}
|
||||
t.Error("Error truncating extra timespans: ", len(cc.Timespans))
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestDebitSMSBalance(t *testing.T) {
|
||||
b1 := &Balance{Value: 10, Weight: 10, DestinationId: "NAT"}
|
||||
|
||||
Reference in New Issue
Block a user