From 6f4e0775ef0d8a7fd5e67a6fd676ecccb016419e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 26 Aug 2021 17:31:42 +0300 Subject: [PATCH] Revert "Updated EventCost rounding increment handling.Fixes #3018" This reverts commit 4fabf8731b0c1cf461d830ebb04903b2f0c71d72. --- engine/eventcost.go | 4 ++-- engine/eventcost_test.go | 12 ++++++------ engine/libeventcost.go | 11 ++++------- engine/libeventcost_test.go | 4 ++-- sessions/sessions_voice_it_test.go | 4 ++-- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/engine/eventcost.go b/engine/eventcost.go index 947812ea2..f9606a77d 100644 --- a/engine/eventcost.go +++ b/engine/eventcost.go @@ -308,7 +308,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.MetaRoundingMiddle) ec.Cost = &cost @@ -408,7 +408,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 60c832c86..63413ce2c 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.MetaVoice, - Cost: 0.85, + Cost: 0.75, RatedUsage: 120.0, Timespans: TimeSpans{ &TimeSpan{ @@ -517,7 +517,7 @@ func TestNewEventCostFromCallCost(t *testing.T) { }, CompressFactor: 1, usage: utils.DurationPointer(60 * time.Second), - cost: utils.Float64Pointer(0.25), + cost: utils.Float64Pointer(0.15), ecUsageIdx: utils.DurationPointer(0), }, { @@ -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", @@ -1746,7 +1746,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)) } @@ -4222,7 +4222,7 @@ func TestECAsCallCost4(t *testing.T) { ToR: utils.MetaVoice, Timespans: TimeSpans{ { - Cost: 0, + Cost: 25, DurationIndex: 250, Increments: Increments{ { diff --git a/engine/libeventcost.go b/engine/libeventcost.go index f64908353..788b5668d 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.MetaRoundingMiddle) 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.MetaRoundingMiddle) } diff --git a/engine/libeventcost_test.go b/engine/libeventcost_test.go index 8b17e3568..4f25e2b42 100644 --- 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 d2414832e..639f8e86b 100644 --- a/sessions/sessions_voice_it_test.go +++ b/sessions/sessions_voice_it_test.go @@ -929,8 +929,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]) } } }