mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 22:58:44 +05:00
count minutes with direction
This commit is contained in:
@@ -376,6 +376,7 @@ The amount filed has to be filled in call descriptor.
|
||||
func (cd *CallDescriptor) AddRecievedCallSeconds() (err error) {
|
||||
if userBalance, err := cd.getUserBalance(); err == nil && userBalance != nil {
|
||||
a := &Action{
|
||||
Direction: INBOUND,
|
||||
MinuteBucket: &MinuteBucket{Seconds: cd.Amount, DestinationId: cd.Destination},
|
||||
}
|
||||
userBalance.countUnits(a)
|
||||
|
||||
@@ -127,7 +127,7 @@ debited and an error will be returned.
|
||||
*/
|
||||
func (ub *UserBalance) debitMinutesBalance(amount float64, prefix string, count bool) error {
|
||||
if count && amount > 0 {
|
||||
ub.countUnits(&Action{BalanceId: MINUTES, MinuteBucket: &MinuteBucket{Seconds: amount, DestinationId: prefix}})
|
||||
ub.countUnits(&Action{BalanceId: MINUTES, Direction: OUTBOUND, MinuteBucket: &MinuteBucket{Seconds: amount, DestinationId: prefix}})
|
||||
}
|
||||
avaliableNbSeconds, _, bucketList := ub.getSecondsForPrefix(prefix)
|
||||
if avaliableNbSeconds < amount {
|
||||
@@ -174,7 +174,7 @@ Debits some amount of user's specified balance. Returns the remaining credit in
|
||||
*/
|
||||
func (ub *UserBalance) debitBalance(balanceId string, amount float64, count bool) float64 {
|
||||
if count && amount > 0 {
|
||||
ub.countUnits(&Action{BalanceId: balanceId, Units: amount})
|
||||
ub.countUnits(&Action{BalanceId: balanceId, Direction: OUTBOUND, Units: amount})
|
||||
}
|
||||
ub.BalanceMap[balanceId+OUTBOUND] -= amount
|
||||
return ub.BalanceMap[balanceId+OUTBOUND]
|
||||
@@ -219,7 +219,7 @@ func (ub *UserBalance) resetActionTriggers() {
|
||||
// Returns the unit counter that matches the specified action type
|
||||
func (ub *UserBalance) getUnitCounter(a *Action) *UnitsCounter {
|
||||
for _, uc := range ub.UnitCounters {
|
||||
if uc.BalanceId == a.BalanceId {
|
||||
if uc.BalanceId == a.BalanceId && uc.Direction == a.Direction {
|
||||
return uc
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func (ub *UserBalance) countUnits(a *Action) {
|
||||
unitsCounter := ub.getUnitCounter(a)
|
||||
// if not found add the counter
|
||||
if unitsCounter == nil {
|
||||
unitsCounter = &UnitsCounter{BalanceId: a.BalanceId}
|
||||
unitsCounter = &UnitsCounter{BalanceId: a.BalanceId, Direction: a.Direction}
|
||||
ub.UnitCounters = append(ub.UnitCounters, unitsCounter)
|
||||
}
|
||||
if a.BalanceId == MINUTES && a.MinuteBucket != nil {
|
||||
|
||||
@@ -395,7 +395,7 @@ func TestUserBalanceExecuteTriggeredActionsOrder(t *testing.T) {
|
||||
ub := &UserBalance{
|
||||
Id: "TEST_UB_OREDER",
|
||||
BalanceMap: map[string]float64{CREDIT + OUTBOUND: 100},
|
||||
UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceId: CREDIT, Units: 1}},
|
||||
UnitCounters: []*UnitsCounter{&UnitsCounter{BalanceId: CREDIT, Direction: OUTBOUND, Units: 1}},
|
||||
ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceId: CREDIT, ThresholdValue: 2, ActionsId: "TEST_ACTIONS_ORDER"}},
|
||||
}
|
||||
ub.countUnits(&Action{BalanceId: CREDIT, Direction: OUTBOUND, Units: 1})
|
||||
|
||||
Reference in New Issue
Block a user