Update correctly the EventCost in case of refund

This commit is contained in:
TeoV
2019-05-31 15:38:11 +03:00
committed by Dan Christian Bogos
parent 393171e601
commit c170910a33
3 changed files with 14 additions and 6 deletions

View File

@@ -607,8 +607,10 @@ func (ec *EventCost) Trim(atUsage time.Duration) (srplusEC *EventCost, err error
return // no trim
}
if atUsage == 0 {
srplusEC = ec
ec = NewBareEventCost()
//clone the event because we need to overwrite ec
srplusEC = ec.Clone()
// modify the value of ec
*ec = *NewBareEventCost()
ec.CGRID = srplusEC.CGRID
ec.RunID = srplusEC.RunID
ec.StartTime = srplusEC.StartTime

View File

@@ -991,15 +991,22 @@ func TestECTrimZeroAndFull(t *testing.T) {
}
eFullSrpls := testEC.Clone()
eFullSrpls.Usage = utils.DurationPointer(time.Duration(10 * time.Minute))
eFullSrpls.Charges[0].usage = utils.DurationPointer(time.Duration(1 * time.Minute))
eFullSrpls.Charges[1].usage = utils.DurationPointer(time.Duration(1 * time.Minute))
eFullSrpls.Charges[2].usage = utils.DurationPointer(time.Duration(1 * time.Minute))
if srplsEC, err := ec.Trim(time.Duration(0)); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eFullSrpls, srplsEC) {
t.Errorf("\tExpecting: %s,\n\treceived: %s",
utils.ToJSON(eFullSrpls), utils.ToJSON(srplsEC))
}
//verify the event cost
newEc := NewBareEventCost()
newEc.CGRID = eFullSrpls.CGRID
newEc.RunID = eFullSrpls.RunID
newEc.StartTime = eFullSrpls.StartTime
newEc.AccountSummary = eFullSrpls.AccountSummary.Clone()
if !reflect.DeepEqual(newEc, ec) {
t.Errorf("\tExpecting: %s,\n\treceived: %s",
utils.ToJSON(newEc), utils.ToJSON(ec))
}
}
func TestECTrimMiddle1(t *testing.T) {

View File

@@ -1451,7 +1451,6 @@ func (sS *SessionS) endSession(s *Session, tUsage, lastUsage *time.Duration, aTi
"<%s> failed refunding session: <%s>, srIdx: <%d>, error: <%s>",
utils.SessionS, s.CGRID, sRunIdx, err.Error()))
}
// FixMe: make sure refund is reflected inside EventCost
}
// set cost fields
sr.Event[utils.Cost] = sr.EventCost.GetCost()