*set_expiry action refactored

This commit is contained in:
TeoV
2018-02-14 13:55:54 +02:00
committed by Dan Christian Bogos
parent bea5803f76
commit ca26da0bc2
2 changed files with 13 additions and 19 deletions

View File

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

View File

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