mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
use old GetCost if no lcr accounts defined
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user