From 1f0931f8f3e308478a718fc1ec2daef8278d69bd Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 30 Aug 2021 17:01:38 +0300 Subject: [PATCH] Revert "Updated EventCost rounding increment handling.Fixes #3018" This reverts commit 6fdc2e56bdebaacde7e281bb71384f0f275d441e. --- engine/eventcost.go | 4 ++-- engine/eventcost_test.go | 14 +++++++------- engine/libeventcost.go | 11 ++++------- engine/libeventcost_test.go | 4 ++-- sessions/sessions_voice_it_test.go | 4 ++-- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/engine/eventcost.go b/engine/eventcost.go index 70a2fcc46..04431a964 100644 --- a/engine/eventcost.go +++ b/engine/eventcost.go @@ -272,7 +272,7 @@ func (ec *EventCost) GetCost() float64 { if ec.Cost == nil { var cost float64 for _, ci := range ec.Charges { - cost += ci.TotalCost(ec.Accounting) + cost += ci.TotalCost() } cost = utils.Round(cost, globalRoundingDecimals, utils.ROUNDING_MIDDLE) ec.Cost = &cost @@ -372,7 +372,7 @@ func (ec *EventCost) AsCallCost(tor string) *CallCost { cc.Timespans = make(TimeSpans, len(ec.Charges)) for i, cIl := range ec.Charges { ts := &TimeSpan{ - Cost: cIl.Cost(ec.Accounting), + Cost: cIl.Cost(), DurationIndex: *cIl.Usage(), CompressFactor: cIl.CompressFactor, } diff --git a/engine/eventcost_test.go b/engine/eventcost_test.go index 8b281c062..a9f5fe51a 100644 --- a/engine/eventcost_test.go +++ b/engine/eventcost_test.go @@ -322,7 +322,7 @@ func TestNewEventCostFromCallCost(t *testing.T) { Account: "dan", Destination: "+4986517174963", ToR: utils.VOICE, - Cost: 0.85, + Cost: 0.75, RatedUsage: 120.0, Timespans: TimeSpans{ &TimeSpan{ @@ -516,9 +516,9 @@ func TestNewEventCostFromCallCost(t *testing.T) { }, }, CompressFactor: 1, - usage: utils.DurationPointer(60 * time.Second), - cost: utils.Float64Pointer(0.25), - ecUsageIdx: utils.DurationPointer(0), + usage: utils.DurationPointer(time.Duration(60 * time.Second)), + cost: utils.Float64Pointer(0.15), + ecUsageIdx: utils.DurationPointer(time.Duration(0)), }, &ChargingInterval{ RatingID: "f2518464-68b8-42f4-acec-aef23d714314", @@ -662,9 +662,9 @@ func TestNewEventCostFromCallCost(t *testing.T) { t.Errorf("Expecting: %v, received: %v", eEC.Charges[i].Usage(), ec.Charges[i].Usage()) } - if !reflect.DeepEqual(eEC.Charges[i].Cost(eEC.Accounting), ec.Charges[i].Cost(ec.Accounting)) { + if !reflect.DeepEqual(eEC.Charges[i].Cost(), ec.Charges[i].Cost()) { t.Errorf("Expecting: %f, received: %f", - eEC.Charges[i].Cost(eEC.Accounting), ec.Charges[i].Cost(ec.Accounting)) + eEC.Charges[i].Cost(), ec.Charges[i].Cost()) } if !reflect.DeepEqual(eEC.Charges[i].ecUsageIdx, ec.Charges[i].ecUsageIdx) { t.Errorf("Expecting: %v, received: %v", @@ -1741,7 +1741,7 @@ func TestECMergeGT(t *testing.T) { } if len(ecGT.Charges) != len(ecExpct.Charges) || !reflect.DeepEqual(ecGT.Charges[0].TotalUsage(), ecExpct.Charges[0].TotalUsage()) || - !reflect.DeepEqual(ecGT.Charges[0].TotalCost(ecGT.Accounting), ecExpct.Charges[0].TotalCost(ecExpct.Accounting)) { + !reflect.DeepEqual(ecGT.Charges[0].TotalCost(), ecExpct.Charges[0].TotalCost()) { t.Errorf("expecting: %s\n\n, received: %s", utils.ToJSON(ecExpct), utils.ToJSON(ecGT)) } diff --git a/engine/libeventcost.go b/engine/libeventcost.go index 6ca4b1994..beb365fc7 100644 --- a/engine/libeventcost.go +++ b/engine/libeventcost.go @@ -94,14 +94,11 @@ func (cIl *ChargingInterval) EndTime(cIlST time.Time) (et time.Time) { } // Cost computes the total cost on this ChargingInterval -func (cIl *ChargingInterval) Cost(ac Accounting) float64 { +func (cIl *ChargingInterval) Cost() float64 { if cIl.cost == nil { var cost float64 for _, incr := range cIl.Increments { - if ac[incr.AccountingID] == nil || // ignore the rounding increment - ac[incr.AccountingID].RatingID != utils.MetaRounding { // only used to justify the diference between the debited price and the final CDR cost - cost += incr.Cost * float64(incr.CompressFactor) - } + cost += incr.Cost * float64(incr.CompressFactor) } cost = utils.Round(cost, globalRoundingDecimals, utils.ROUNDING_MIDDLE) cIl.cost = &cost @@ -110,8 +107,8 @@ func (cIl *ChargingInterval) Cost(ac Accounting) float64 { } // TotalCost returns the cost of charges -func (cIl *ChargingInterval) TotalCost(ac Accounting) float64 { - return utils.Round((cIl.Cost(ac) * float64(cIl.CompressFactor)), +func (cIl *ChargingInterval) TotalCost() float64 { + return utils.Round((cIl.Cost() * float64(cIl.CompressFactor)), globalRoundingDecimals, utils.ROUNDING_MIDDLE) } diff --git a/engine/libeventcost_test.go b/engine/libeventcost_test.go index 9af386ff7..b8d62917a 100755 --- a/engine/libeventcost_test.go +++ b/engine/libeventcost_test.go @@ -266,7 +266,7 @@ func TestChargingIntervalCost(t *testing.T) { }, CompressFactor: 3, } - tCi1 := ci1.Cost(Accounting{"Acc1": {}}) + tCi1 := ci1.Cost() eTCi1 := 10.84 if tCi1 != eTCi1 { t.Errorf("Expecting: %+v, received: %+v", eTCi1, tCi1) @@ -298,7 +298,7 @@ func TestChargingIntervalTotalCost(t *testing.T) { }, CompressFactor: 3, } - tCi1 := ci1.TotalCost(Accounting{"Acc1": {}}) + tCi1 := ci1.TotalCost() eTCi1 := 32.52 if tCi1 != eTCi1 { t.Errorf("Expecting: %+v, received: %+v", eTCi1, tCi1) diff --git a/sessions/sessions_voice_it_test.go b/sessions/sessions_voice_it_test.go index 71f1f596f..d0dfcc53a 100644 --- a/sessions/sessions_voice_it_test.go +++ b/sessions/sessions_voice_it_test.go @@ -934,8 +934,8 @@ func testSessionsVoiceSessionTTL(t *testing.T) { if cdrs[0].Usage != "2m30.05s" { t.Errorf("Unexpected CDR Usage received, cdr: %v %+v ", cdrs[0].Usage, cdrs[0]) } - if cdrs[0].Cost != 1.5333 { - t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, utils.ToJSON(cdrs[0])) + if cdrs[0].Cost != 1.5332 { + t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, cdrs[0]) } } }