This commit is contained in:
DanB
2015-11-10 11:53:54 +01:00
4 changed files with 11 additions and 6 deletions

View File

@@ -195,6 +195,11 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
for idx, actId := range actIds {
actKeys[idx] = utils.ACTION_PREFIX + actId
}
aplIds, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX)
aplKeys := make([]string, len(aplIds))
for idx, aplId := range aplIds {
aplKeys[idx] = utils.ACTION_PLAN_PREFIX + aplId
}
shgIds, _ := loader.GetLoadedIds(utils.SHARED_GROUP_PREFIX)
shgKeys := make([]string, len(shgIds))
for idx, shgId := range shgIds {
@@ -225,6 +230,7 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
utils.LCR_PREFIX: lcrKeys,
utils.DERIVEDCHARGERS_PREFIX: dcsKeys,
utils.ACTION_PREFIX: actKeys,
utils.ACTION_PLAN_PREFIX: aplKeys,
utils.SHARED_GROUP_PREFIX: shgKeys,
}); err != nil {
return err

View File

@@ -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

View File

@@ -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)

View File

@@ -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 (