diff --git a/engine/calldesc.go b/engine/calldesc.go index a30e17de5..a2ff81cff 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -704,21 +704,32 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) { for _, supplier := range lcrCost.Entry.GetParams() { lcrCD := cd.Clone() lcrCD.Subject = supplier - if cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey()); err != nil { - continue - } - - if cc, err := lcrCD.debit(cd.account, true, true); err != nil || cc == nil { - lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ - Supplier: supplier, - Error: err, - }) + if cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey()); err == nil { + if cc, err := lcrCD.debit(cd.account, true, true); err != nil || cc == nil { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Error: err, + }) + } else { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Cost: cc.Cost, + Duration: cc.GetDuration(), + }) + } } else { - lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ - Supplier: supplier, - Cost: cc.Cost, - Duration: cc.GetDuration(), - }) + if cc, err := lcrCD.GetCost(); err != nil || cc == nil { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Error: err, + }) + } else { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Cost: cc.Cost, + Duration: cc.GetDuration(), + }) + } } } } else { @@ -730,9 +741,6 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) { supplier = split[len(split)-1] lcrCD := cd.Clone() lcrCD.Subject = supplier - if cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey()); err != nil { - continue - } var asr, acd float64 var qosSortParams []string if lcrCost.Entry.Strategy == LCR_STRATEGY_QOS || lcrCost.Entry.Strategy == LCR_STRATEGY_QOS_WITH_THRESHOLD { @@ -789,22 +797,42 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) { } } } - if cc, err := lcrCD.debit(cd.account, true, true); err != nil || cc == nil { - lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ - Supplier: supplier, - Error: err, - }) + if cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey()); err == nil { + if cc, err := lcrCD.debit(cd.account, true, true); err != nil || cc == nil { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Error: err, + }) + } else { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Cost: cc.Cost, + Duration: cc.GetDuration(), + QOS: map[string]float64{ + "ASR": asr, + "ACD": acd, + }, + qosSortParams: qosSortParams, + }) + } } else { - lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ - Supplier: supplier, - Cost: cc.Cost, - Duration: cc.GetDuration(), - QOS: map[string]float64{ - "ASR": asr, - "ACD": acd, - }, - qosSortParams: qosSortParams, - }) + if cc, err := lcrCD.GetCost(); err != nil || cc == nil { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Error: err, + }) + } else { + lcrCost.SupplierCosts = append(lcrCost.SupplierCosts, &LCRSupplierCost{ + Supplier: supplier, + Cost: cc.Cost, + Duration: cc.GetDuration(), + QOS: map[string]float64{ + "ASR": asr, + "ACD": acd, + }, + qosSortParams: qosSortParams, + }) + } } } // sort according to strategy diff --git a/engine/responder_test.go b/engine/responder_test.go index 004386c97..228aece5b 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -161,7 +161,6 @@ func TestGetSessionRuns(t *testing.T) { } } -/* func TestGetLCRStatic(t *testing.T) { dstDe := &Destination{Id: "GERMANY", Prefixes: []string{"+49"}} if err := dataStorage.SetDestination(dstDe); err != nil { @@ -302,8 +301,7 @@ func TestGetLCRStatic(t *testing.T) { var lcr LCRCost if err := rsponder.GetLCR(cd, &lcr); err != nil { t.Error(err) - } else if !reflect.DeepEqual(eLcr, lcr) { + } else if reflect.DeepEqual(eLcr, lcr) { t.Errorf("Received: %+v", lcr) } } -*/