mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Console AddBalance with Weight
This commit is contained in:
@@ -93,6 +93,7 @@ type AttrAddBalance struct {
|
||||
BalanceId string
|
||||
Direction string
|
||||
Value float64
|
||||
Weight float64
|
||||
Overwrite bool // When true it will reset if the balance is already there
|
||||
}
|
||||
|
||||
@@ -119,7 +120,8 @@ 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}}})
|
||||
at.SetActions(engine.Actions{&engine.Action{ActionType: aType, BalanceId: attr.BalanceId, Direction: attr.Direction,
|
||||
Balance: &engine.Balance{Value: attr.Value, Weight: attr.Weight}}})
|
||||
if err := at.Execute(); err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
|
||||
@@ -38,7 +38,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> <value> [<balanceid=monetary|sms|internet|internet_time|minutes> [<direction> [overwrite]]]")
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance <tenant> <account> <value> [<balanceid=monetary|sms|internet|internet_time|minutes> [<weight> [overwrite]]]")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
@@ -51,6 +51,7 @@ func (self *CmdAddBalance) defaults() error {
|
||||
|
||||
// Parses command line args and builds CmdBalance value
|
||||
func (self *CmdAddBalance) FromArgs(args []string) error {
|
||||
var err error
|
||||
if len(args) < 5 {
|
||||
return fmt.Errorf(self.Usage(""))
|
||||
}
|
||||
@@ -67,7 +68,9 @@ func (self *CmdAddBalance) FromArgs(args []string) error {
|
||||
self.rpcParams.BalanceId = args[5]
|
||||
}
|
||||
if len(args) > 6 {
|
||||
self.rpcParams.Direction = args[6]
|
||||
if self.rpcParams.Weight, err = strconv.ParseFloat(args[6], 64); err != nil {
|
||||
return fmt.Errorf("Cannot parse weight parameter")
|
||||
}
|
||||
}
|
||||
if len(args) > 7 {
|
||||
if args[7] == "overwrite" {
|
||||
|
||||
Reference in New Issue
Block a user