diff --git a/engine/callcost.go b/engine/callcost.go index 19a02bd3b..238619491 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -20,7 +20,6 @@ package engine import ( "encoding/json" "errors" - "reflect" "time" "github.com/cgrates/cgrates/utils" @@ -37,21 +36,7 @@ type CallCost struct { // Merges the received timespan if they are similar (same activation period, same interval, same minute info. func (cc *CallCost) Merge(other *CallCost) { - if len(cc.Timespans)-1 < 0 || len(other.Timespans) == 0 { - return - } - ts := cc.Timespans[len(cc.Timespans)-1] - otherTs := other.Timespans[0] - if reflect.DeepEqual(ts.ratingInfo, otherTs.ratingInfo) && - reflect.DeepEqual(ts.RateInterval, otherTs.RateInterval) { - // extend the last timespan with - ts.TimeEnd = ts.TimeEnd.Add(otherTs.GetDuration()) - // add the rest of the timspans - cc.Timespans = append(cc.Timespans, other.Timespans[1:]...) - } else { - // just add all timespans - cc.Timespans = append(cc.Timespans, other.Timespans...) - } + cc.Timespans = append(cc.Timespans, other.Timespans...) cc.Cost += other.Cost } diff --git a/engine/callcost_test.go b/engine/callcost_test.go index 5349b104b..6b3d6701f 100644 --- a/engine/callcost_test.go +++ b/engine/callcost_test.go @@ -121,8 +121,8 @@ func TestMultipleInputRightMerge(t *testing.T) { t.Errorf("expected 91 was %v", cc2.Cost) } cc1.Merge(cc2) - if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 120 { - t.Error("wrong resulted timespan: ", len(cc1.Timespans)) + if len(cc1.Timespans) != 3 || cc1.Timespans[0].GetDuration().Seconds() != 60 { + t.Error("wrong resulted timespan: ", len(cc1.Timespans), cc1.Timespans[0].GetDuration().Seconds()) } if cc1.Cost != 152 { t.Errorf("Exdpected 152 was %v", cc1.Cost) diff --git a/sessionmanager/session.go b/sessionmanager/session.go index 5a378ca3d..e117112e9 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -217,8 +217,11 @@ func (s *Session) SaveOperations() { } firstCC := sr.CallCosts[0] for _, cc := range sr.CallCosts[1:] { + engine.Logger.Debug(fmt.Sprintf("BEFORE MERGE: %+v", firstCC)) firstCC.Merge(cc) + engine.Logger.Debug(fmt.Sprintf("AFTER MERGE: %+v", firstCC)) } + var reply string err := s.sessionManager.CdrSrv().LogCallCost(&engine.CallCostLog{ CgrId: s.eventStart.GetCgrId(),