mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
fix for *voice balances refund
This commit is contained in:
@@ -743,22 +743,33 @@ func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
|
||||
|
||||
func (cd *CallDescriptor) RefundIncrements() (left float64, err error) {
|
||||
cd.account = nil // make sure it's not cached
|
||||
accountsCache := make(map[string]*Account)
|
||||
// get account list for locking
|
||||
// all must be locked in order to use cache
|
||||
var accountIDs []string
|
||||
for _, increment := range cd.Increments {
|
||||
account, found := accountsCache[increment.BalanceInfo.AccountId]
|
||||
Guardian.Guard(func() (interface{}, error) {
|
||||
accountIDs = append(accountIDs, increment.BalanceInfo.AccountId)
|
||||
}
|
||||
Guardian.Guard(func() (interface{}, error) {
|
||||
accountsCache := make(map[string]*Account)
|
||||
for _, increment := range cd.Increments {
|
||||
account, found := accountsCache[increment.BalanceInfo.AccountId]
|
||||
if !found {
|
||||
if acc, err := accountingStorage.GetAccount(increment.BalanceInfo.AccountId); err == nil && acc != nil {
|
||||
account = acc
|
||||
accountsCache[increment.BalanceInfo.AccountId] = account
|
||||
// will save the account only once at the end of the function
|
||||
defer accountingStorage.SetAccount(account)
|
||||
}
|
||||
}
|
||||
utils.Logger.Info(fmt.Sprintf("Refunding increment %+v", increment))
|
||||
if account == nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not get the account to be refunded: %s", increment.BalanceInfo.AccountId))
|
||||
continue
|
||||
}
|
||||
//utils.Logger.Info(fmt.Sprintf("Refunding increment %+v", increment))
|
||||
account.refundIncrement(increment, cd, true)
|
||||
return 0, err
|
||||
}, 0, increment.BalanceInfo.AccountId)
|
||||
}
|
||||
}
|
||||
return 0, err
|
||||
}, 0, accountIDs...)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,7 @@ func (s *Session) Refund(lastCC *engine.CallCost, hangupTime time.Time) error {
|
||||
Subject: lastCC.Subject,
|
||||
Account: lastCC.Account,
|
||||
Destination: lastCC.Destination,
|
||||
TOR: lastCC.TOR,
|
||||
Increments: refundIncrements,
|
||||
}
|
||||
var response float64
|
||||
|
||||
@@ -111,6 +111,9 @@ func TestSMGTPFromFolder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSMGMonetaryRefound(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
smgEv := SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
@@ -171,6 +174,9 @@ func TestSMGMonetaryRefound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSMGVoiceRefound(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
smgEv := SMGenericEvent{
|
||||
utils.EVENT_NAME: "TEST_EVENT",
|
||||
utils.TOR: utils.VOICE,
|
||||
|
||||
@@ -152,6 +152,7 @@ func (self *SMGSession) refund(refundDuration time.Duration) error {
|
||||
Subject: lastCC.Subject,
|
||||
Account: lastCC.Account,
|
||||
Destination: lastCC.Destination,
|
||||
TOR: lastCC.TOR,
|
||||
Increments: refundIncrements,
|
||||
}
|
||||
var response float64
|
||||
|
||||
Reference in New Issue
Block a user