mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Revise CDR rerating
If the reRate parameter is set to true, also set the refund to true. In case CostDetails is not populated, before attempting to refund try to retrieve it from StorDB. Now that the refund happens before the debit, revise the expected values for the testV1CDRsProcessEventWithRefund subtest within the apier/v1/cdrs_it_test.go file.
This commit is contained in:
committed by
Dan Christian Bogos
parent
311d01861d
commit
d262aaac8b
@@ -237,12 +237,11 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) {
|
||||
}
|
||||
if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 120000000000 { // refund is done after debit
|
||||
} else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 60000000000 {
|
||||
t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1))
|
||||
} else if blc2 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE2"); blc2.Value != 120000000000 {
|
||||
} else if blc2 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE2"); blc2.Value != 180000000000 {
|
||||
t.Errorf("Balance2 is: %s", utils.ToIJSON(blc2))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func testV1CDRsRefundOutOfSessionCost(t *testing.T) {
|
||||
|
||||
@@ -439,6 +439,9 @@ func (cdrS *CDRServer) eeSProcessEvent(cgrEv *CGREventWithEeIDs) (err error) {
|
||||
// in case of partially executed, both error and evs will be returned
|
||||
func (cdrS *CDRServer) processEvents(evs []*utils.CGREvent,
|
||||
chrgS, attrS, refund, ralS, store, reRate, export, thdS, stS bool) (outEvs []*utils.EventWithFlags, err error) {
|
||||
if reRate {
|
||||
refund = true
|
||||
}
|
||||
if attrS {
|
||||
for _, ev := range evs {
|
||||
if err = cdrS.attrSProcessEvent(ev); err != nil {
|
||||
@@ -513,6 +516,18 @@ func (cdrS *CDRServer) processEvents(evs []*utils.CGREvent,
|
||||
}
|
||||
if refund {
|
||||
for i, cdr := range cdrs {
|
||||
if cdr.CostDetails == nil { // if CostDetails is not populated, look for it inside the previously stored cdr
|
||||
var prevCDRs []*CDR // only one should be returned
|
||||
if prevCDRs, _, err = cdrS.cdrDb.GetCDRs(
|
||||
&utils.CDRsFilter{CGRIDs: []string{cdr.CGRID},
|
||||
RunIDs: []string{cdr.RunID}}, false); err != nil {
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s> could not retrieve previously stored CDR, error: <%s>",
|
||||
utils.CDRs, err.Error()))
|
||||
continue
|
||||
}
|
||||
cdr.CostDetails = prevCDRs[0].CostDetails
|
||||
}
|
||||
if rfnd, errRfd := cdrS.refundEventCost(cdr.CostDetails,
|
||||
cdr.RequestType, cdr.ToR); errRfd != nil {
|
||||
utils.Logger.Warning(
|
||||
@@ -1088,7 +1103,7 @@ func (cdrS *CDRServer) V1RateCDRs(arg *ArgRateCDRs, reply *string) (err error) {
|
||||
cgrEvs[i] = cdr.AsCGREvent()
|
||||
cgrEvs[i].APIOpts = arg.APIOpts
|
||||
}
|
||||
if _, err = cdrS.processEvents(cgrEvs, chrgS, attrS, true,
|
||||
if _, err = cdrS.processEvents(cgrEvs, chrgS, attrS, false,
|
||||
true, store, true, export, thdS, statS); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user