mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
*set_expiry action refactored
This commit is contained in:
committed by
Dan Christian Bogos
parent
bea5803f76
commit
ca26da0bc2
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user