mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 16:18:44 +05:00
more rounding and maxxsession improvement
This commit is contained in:
@@ -102,6 +102,7 @@ func (ub *Account) debitBalanceAction(a *Action) error {
|
||||
}
|
||||
if b.Equal(a.Balance) {
|
||||
b.Value -= a.Balance.Value
|
||||
b.Value = utils.Round(b.Value, roundingDecimals, utils.ROUNDING_MIDDLE)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -240,6 +241,7 @@ CONNECT_FEE:
|
||||
for _, b := range usefulMoneyBalances {
|
||||
if b.Value >= amount {
|
||||
b.Value -= amount
|
||||
b.Value = utils.Round(b.Value, roundingDecimals, utils.ROUNDING_MIDDLE)
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceType: CREDIT, Direction: cc.Direction, Balance: &Balance{Value: amount, DestinationId: cc.Destination}})
|
||||
@@ -378,9 +380,7 @@ func (ub *Account) refundIncrements(increments Increments, direction string, cou
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Debits some amount of user's specified balance. Returns the remaining credit in user's balance.
|
||||
*/
|
||||
// Debits some amount of user's specified balance. Returns the remaining credit in user's balance.
|
||||
func (ub *Account) debitGenericBalance(balanceId string, direction string, amount float64, count bool) float64 {
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceType: balanceId, Direction: direction, Balance: &Balance{Value: amount}})
|
||||
|
||||
@@ -1032,27 +1032,8 @@ func TestAccountRefund(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopupAction(t *testing.T) {
|
||||
initialUb, _ := accountingStorage.GetAccount("*out:vdf:minu")
|
||||
a := &Action{
|
||||
ActionType: "*topup",
|
||||
BalanceType: CREDIT,
|
||||
Direction: OUTBOUND,
|
||||
Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20},
|
||||
}
|
||||
func TestDebitShared(t *testing.T) {
|
||||
|
||||
at := &ActionTiming{
|
||||
AccountIds: []string{"*out:vdf:minu"},
|
||||
actions: Actions{a},
|
||||
}
|
||||
|
||||
at.Execute()
|
||||
afterUb, _ := accountingStorage.GetAccount("*out:vdf:minu")
|
||||
initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
|
||||
afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
|
||||
if initialValue != 50 || afterValue != 75 {
|
||||
t.Error("Bad topup before and after: ", initialValue, afterValue)
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************** Benchmarks *******************************/
|
||||
|
||||
@@ -955,8 +955,27 @@ func TestActionMakeNegative(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinBalanceTriggerSimple(t *testing.T) {
|
||||
//ub := &Account{}
|
||||
func TestTopupAction(t *testing.T) {
|
||||
initialUb, _ := accountingStorage.GetAccount("*out:vdf:minu")
|
||||
a := &Action{
|
||||
ActionType: "*topup",
|
||||
BalanceType: CREDIT,
|
||||
Direction: OUTBOUND,
|
||||
Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20},
|
||||
}
|
||||
|
||||
at := &ActionTiming{
|
||||
AccountIds: []string{"*out:vdf:minu"},
|
||||
actions: Actions{a},
|
||||
}
|
||||
|
||||
at.Execute()
|
||||
afterUb, _ := accountingStorage.GetAccount("*out:vdf:minu")
|
||||
initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
|
||||
afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
|
||||
if initialValue != 50 || afterValue != 75 {
|
||||
t.Error("Bad topup before and after: ", initialValue, afterValue)
|
||||
}
|
||||
}
|
||||
|
||||
/********************************** Benchmarks ********************************/
|
||||
|
||||
@@ -436,7 +436,7 @@ If the user has postpayed plan it returns -1.
|
||||
*/
|
||||
func (origCd *CallDescriptor) GetMaxSessionDuration() (time.Duration, error) {
|
||||
cd := origCd.Clone()
|
||||
if cd.CallDuration == 0 {
|
||||
if cd.CallDuration < cd.TimeEnd.Sub(cd.TimeStart) {
|
||||
cd.CallDuration = cd.TimeEnd.Sub(cd.TimeStart)
|
||||
}
|
||||
//Logger.Debug(fmt.Sprintf("MAX SESSION cd: %+v", cd))
|
||||
|
||||
Reference in New Issue
Block a user