removed direction and added destinationid to add_balance console command

th consoled is aimed to be used for simple and quick test actions
This commit is contained in:
Radu Ioan Fericean
2014-02-03 17:34:37 +02:00
parent 5f331f3161
commit 20a0ae4449
3 changed files with 31 additions and 13 deletions

View File

@@ -21,12 +21,13 @@ package apier
import (
"errors"
"fmt"
"path"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/scheduler"
"github.com/cgrates/cgrates/utils"
"path"
)
const (
@@ -93,8 +94,11 @@ type AttrAddBalance struct {
BalanceId string
Direction string
Value float64
Weight float64
Overwrite bool // When true it will reset if the balance is already there
//ExpirationDate time.Time
//RateSubject string
DestinationId string
Weight float64
Overwrite bool // When true it will reset if the balance is already there
}
func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
@@ -120,8 +124,20 @@ func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
if attr.Overwrite {
aType = engine.TOPUP_RESET
}
at.SetActions(engine.Actions{&engine.Action{ActionType: aType, BalanceId: attr.BalanceId, Direction: attr.Direction,
Balance: &engine.Balance{Value: attr.Value, Weight: attr.Weight}}})
at.SetActions(engine.Actions{
&engine.Action{
ActionType: aType,
BalanceId: attr.BalanceId,
Direction: attr.Direction,
Balance: &engine.Balance{
Value: attr.Value,
//ExpirationDate: attr.ExpirationDate,
//RateSubject: attr.RateSubject,
DestinationId: attr.DestinationId,
Weight: attr.Weight,
},
},
})
if err := at.Execute(); err != nil {
*reply = err.Error()
return err

View File

@@ -39,7 +39,7 @@ type CmdAddBalance struct {
// name should be exec's name
func (self *CmdAddBalance) Usage(name string) string {
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance <tenant> <account> <direction> <value> [<balanceid=monetary|sms|internet|internet_time|minutes> [<weight> [overwrite]]]")
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance <tenant> <account> <value> [monetary|sms|internet|internet_time|minutes [<destinationid> [<weight> [overwrite]]]]")
}
// set param defaults
@@ -60,14 +60,16 @@ func (self *CmdAddBalance) FromArgs(args []string) error {
self.defaults()
self.rpcParams.Tenant = args[2]
self.rpcParams.Account = args[3]
self.rpcParams.Direction = args[4]
value, err := strconv.ParseFloat(args[5], 64)
value, err := strconv.ParseFloat(args[4], 64)
if err != nil {
return err
}
self.rpcParams.Value = value
if len(args) > 5 {
self.rpcParams.BalanceId = args[5]
}
if len(args) > 6 {
self.rpcParams.BalanceId = args[6]
self.rpcParams.DestinationId = args[6]
}
if len(args) > 7 {
if self.rpcParams.Weight, err = strconv.ParseFloat(args[7], 64); err != nil {

View File

@@ -32,10 +32,10 @@ type Balance struct {
Value float64
ExpirationDate time.Time
Weight float64
GroupIds []string
DestinationId string
RateSubject string
precision int
//GroupIds []string
DestinationId string
RateSubject string
precision int
}
func (b *Balance) Equal(o *Balance) bool {