diff --git a/engine/account.go b/engine/account.go index a7843b012..3f8f22811 100644 --- a/engine/account.go +++ b/engine/account.go @@ -100,7 +100,6 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error { } found := false id := a.BalanceType - ub.CleanExpiredBalances() for _, b := range ub.BalanceMap[id] { if b.IsExpired() { continue // just to be safe (cleaned expired balances above) @@ -172,7 +171,6 @@ func (ub *Account) enableDisableBalanceAction(a *Action) error { } found := false id := a.BalanceType - ub.CleanExpiredBalances() for _, b := range ub.BalanceMap[id] { if b.MatchFilter(a.Balance, false) { b.Disabled = a.Balance.Disabled @@ -501,7 +499,7 @@ func (ub *Account) executeActionTriggers(a *Action) { } } else { // BALANCE for _, b := range ub.BalanceMap[at.BalanceType] { - if !b.dirty && at.ThresholdType != utils.TRIGGER_EXP_BALANCE { // do not check clean balances + if !b.dirty && at.ThresholdType != utils.TRIGGER_BALANCE_EXPIRED { // do not check clean balances continue } switch at.ThresholdType { @@ -514,7 +512,7 @@ func (ub *Account) executeActionTriggers(a *Action) { if b.MatchActionTrigger(at) && b.GetValue() <= at.ThresholdValue { at.Execute(ub, nil) } - case utils.TRIGGER_EXP_BALANCE: + case utils.TRIGGER_BALANCE_EXPIRED: if b.MatchActionTrigger(at) && b.IsExpired() { at.Execute(ub, nil) } @@ -522,6 +520,7 @@ func (ub *Account) executeActionTriggers(a *Action) { } } } + ub.CleanExpiredBalances() } // Mark all action trigers as ready for execution diff --git a/engine/account_test.go b/engine/account_test.go index 6b0ccdfff..ab6d7647a 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -970,7 +970,7 @@ func TestAccountExpActionTrigger(t *testing.T) { Id: "TEST_UB", BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100, ExpirationDate: time.Date(2015, time.November, 9, 9, 48, 0, 0, time.UTC)}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}, Directions: utils.StringMap{utils.OUT: true}}, &Balance{Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}}, ActionTriggers: ActionTriggers{ - &ActionTrigger{Id: "check expired balances", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_EXP_BALANCE, ActionsId: "TEST_ACTIONS"}, + &ActionTrigger{Id: "check expired balances", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_BALANCE_EXPIRED, ActionsId: "TEST_ACTIONS"}, }, } ub.executeActionTriggers(nil) diff --git a/utils/consts.go b/utils/consts.go index eec5f79fd..c5b399b78 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -253,7 +253,7 @@ const ( TRIGGER_MAX_BALANCE_COUNTER = "*max_balance_counter" TRIGGER_MIN_BALANCE = "*min_balance" TRIGGER_MAX_BALANCE = "*max_balance" - TRIGGER_EXP_BALANCE = "*exp_balance" + TRIGGER_BALANCE_EXPIRED = "*balance_expired" ) var (