From ca26da0bc2744650fc73612dc8d0843ae348156e Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 14 Feb 2018 13:55:54 +0200 Subject: [PATCH] *set_expiry action refactored --- engine/account.go | 23 +++++++---------------- engine/action.go | 9 ++++++--- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/engine/account.go b/engine/account.go index 0c433de7b..f0acff4fa 100644 --- a/engine/account.go +++ b/engine/account.go @@ -203,23 +203,14 @@ func (ub *Account) debitBalanceAction(a *Action, reset, resetIfNegative, resetEx continue // just to be safe (cleaned expired balances above) } b.account = ub - //if resetExpiry if false we do normal match otherwise modify - if resetExpiry { - if b.MatchFilter(a.Balance, false, resetExpiry) { - b.ExpirationDate = a.Balance.GetExpirationDate() - b.dirty = true - found = true - } - } else { - if b.MatchFilter(a.Balance, false, resetExpiry) { - if reset || (resetIfNegative && b.Value < 0) { - b.SetValue(0) - } - b.SubstractValue(bClone.GetValue()) - b.dirty = true - found = true - a.balanceValue = b.GetValue() + if b.MatchFilter(a.Balance, false, resetExpiry) { + if reset || (resetIfNegative && b.Value < 0) { + b.SetValue(0) } + b.SubstractValue(bClone.GetValue()) + b.dirty = true + found = true + a.balanceValue = b.GetValue() } } // if it is not found then we add it to the list diff --git a/engine/action.go b/engine/action.go index 1778f1e36..5b337dfff 100644 --- a/engine/action.go +++ b/engine/action.go @@ -764,10 +764,13 @@ func setExpiryAction(account *Account, sq *CDRStatsQueueTriggered, a *Action, ac if account == nil { return errors.New("nil account") } - if account.BalanceMap == nil { - account.BalanceMap = make(map[string]Balances) + balanceType := a.Balance.GetType() + for _, b := range account.BalanceMap[balanceType] { + if b.MatchFilter(a.Balance, false, true) { + b.ExpirationDate = a.Balance.GetExpirationDate() + } } - return account.debitBalanceAction(a, false, false, true) + return nil } // Structure to store actions according to weight