mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
Make units/increment accept strinjg of time
This commit is contained in:
committed by
Dan Christian Bogos
parent
768fcde9f9
commit
a2110f8525
@@ -312,7 +312,7 @@ CREATE TABLE tp_accounts (
|
||||
`balance_filter_ids` varchar(64) NOT NULL,
|
||||
`balance_weights` varchar(64) NOT NULL,
|
||||
`balance_type` varchar(64) NOT NULL,
|
||||
`balance_units` decimal(16,4) NOT NULL,
|
||||
`balance_units` varchar(64) NOT NULL,
|
||||
`balance_unit_factors` varchar(64) NOT NULL,
|
||||
`balance_opts` varchar(256) NOT NULL,
|
||||
`balance_cost_increments` varchar(64) NOT NULL,
|
||||
|
||||
@@ -299,7 +299,7 @@ CREATE TABLE tp_accounts (
|
||||
"balance_filter_ids" varchar(64) NOT NULL,
|
||||
"balance_weights" varchar(64) NOT NULL,
|
||||
"balance_type" varchar(64) NOT NULL,
|
||||
"balance_units" decimal(16,4) NOT NULL,
|
||||
"balance_units" varchar(64) NOT NULL,
|
||||
"balance_unit_factors" varchar(64) NOT NULL,
|
||||
"balance_opts" varchar(256) NOT NULL,
|
||||
"balance_cost_increments" varchar(64) NOT NULL,
|
||||
|
||||
@@ -2402,7 +2402,13 @@ func APItoAccount(tpAp *utils.TPAccount, timezone string) (ap *utils.Account, er
|
||||
ID: bal.ID,
|
||||
FilterIDs: bal.FilterIDs,
|
||||
Type: bal.Type,
|
||||
Units: utils.NewDecimalFromFloat64(bal.Units),
|
||||
}
|
||||
if bal.Units != utils.EmptyString {
|
||||
units, err := utils.NewDecimalFromUsage(bal.Units)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ap.Balances[id].Units = units
|
||||
}
|
||||
if bal.Weights != utils.EmptyString {
|
||||
weight, err := utils.NewDynamicWeightsFromString(bal.Weights, utils.InfieldSep, utils.ANDSep)
|
||||
@@ -2437,8 +2443,8 @@ func APItoAccount(tpAp *utils.TPAccount, timezone string) (ap *utils.Account, er
|
||||
ap.Balances[id].CostIncrements[j] = &utils.CostIncrement{
|
||||
FilterIDs: costIncrement.FilterIDs,
|
||||
}
|
||||
if costIncrement.Increment != nil {
|
||||
ap.Balances[id].CostIncrements[j].Increment = utils.NewDecimalFromFloat64(*costIncrement.Increment)
|
||||
if costIncrement.Increment != utils.EmptyString {
|
||||
ap.Balances[id].CostIncrements[j].Increment, err = utils.NewDecimalFromUsage(costIncrement.Increment)
|
||||
}
|
||||
if costIncrement.FixedFee != nil {
|
||||
ap.Balances[id].CostIncrements[j].FixedFee = utils.NewDecimalFromFloat64(*costIncrement.FixedFee)
|
||||
@@ -2485,6 +2491,7 @@ func AccountToAPI(ap *utils.Account) (tpAp *utils.TPAccount) {
|
||||
FilterIDs: make([]string, len(bal.FilterIDs)),
|
||||
Weights: bal.Weights.String(utils.InfieldSep, utils.ANDSep),
|
||||
Type: bal.Type,
|
||||
Units: bal.Units.String(),
|
||||
CostIncrement: make([]*utils.TPBalanceCostIncrement, len(bal.CostIncrements)),
|
||||
AttributeIDs: make([]string, len(bal.AttributeIDs)),
|
||||
RateProfileIDs: make([]string, len(bal.RateProfileIDs)),
|
||||
@@ -2494,7 +2501,6 @@ func AccountToAPI(ap *utils.Account) (tpAp *utils.TPAccount) {
|
||||
tpAp.Balances[i].FilterIDs[k] = fli
|
||||
}
|
||||
//there should not be an invalid value of converting into float64
|
||||
tpAp.Balances[i].Units, _ = bal.Units.Float64()
|
||||
elems := make([]string, 0, len(bal.Opts))
|
||||
for k, v := range bal.Opts {
|
||||
elems = append(elems, utils.ConcatenatedKey(k, utils.IfaceAsString(v)))
|
||||
@@ -2502,15 +2508,11 @@ func AccountToAPI(ap *utils.Account) (tpAp *utils.TPAccount) {
|
||||
for k, cIncrement := range bal.CostIncrements {
|
||||
tpAp.Balances[i].CostIncrement[k] = &utils.TPBalanceCostIncrement{
|
||||
FilterIDs: make([]string, len(cIncrement.FilterIDs)),
|
||||
Increment: cIncrement.Increment.String(),
|
||||
}
|
||||
for kk, fli := range cIncrement.FilterIDs {
|
||||
tpAp.Balances[i].CostIncrement[k].FilterIDs[kk] = fli
|
||||
}
|
||||
if cIncrement.Increment != nil {
|
||||
//there should not be an invalid value of converting from Decimal into float64
|
||||
incr, _ := cIncrement.Increment.Float64()
|
||||
tpAp.Balances[i].CostIncrement[k].Increment = &incr
|
||||
}
|
||||
if cIncrement.FixedFee != nil {
|
||||
//there should not be an invalid value of converting from Decimal into float64
|
||||
fxdFee, _ := cIncrement.FixedFee.Float64()
|
||||
|
||||
@@ -352,22 +352,22 @@ func (ActionProfileMdl) TableName() string {
|
||||
type AccountMdl struct {
|
||||
PK uint `gorm:"primary_key"`
|
||||
Tpid string
|
||||
Tenant string `index:"0" re:""`
|
||||
ID string `index:"1" re:""`
|
||||
FilterIDs string `index:"2" re:""`
|
||||
Weights string `index:"3" re:""`
|
||||
Opts string `index:"4" re:""`
|
||||
BalanceID string `index:"5" re:""`
|
||||
BalanceFilterIDs string `index:"6" re:""`
|
||||
BalanceWeights string `index:"7" re:""`
|
||||
BalanceType string `index:"8" re:""`
|
||||
BalanceUnits float64 `index:"9" re:"\d+\.?\d*"`
|
||||
BalanceUnitFactors string `index:"10" re:""`
|
||||
BalanceOpts string `index:"11" re:""`
|
||||
BalanceCostIncrements string `index:"12" re:""`
|
||||
BalanceAttributeIDs string `index:"13" re:""`
|
||||
BalanceRateProfileIDs string `index:"14" re:""`
|
||||
ThresholdIDs string `index:"15" re:""`
|
||||
Tenant string `index:"0" re:""`
|
||||
ID string `index:"1" re:""`
|
||||
FilterIDs string `index:"2" re:""`
|
||||
Weights string `index:"3" re:""`
|
||||
Opts string `index:"4" re:""`
|
||||
BalanceID string `index:"5" re:""`
|
||||
BalanceFilterIDs string `index:"6" re:""`
|
||||
BalanceWeights string `index:"7" re:""`
|
||||
BalanceType string `index:"8" re:""`
|
||||
BalanceUnits string `index:"9" re:"\d+\.?\d*"`
|
||||
BalanceUnitFactors string `index:"10" re:""`
|
||||
BalanceOpts string `index:"11" re:""`
|
||||
BalanceCostIncrements string `index:"12" re:""`
|
||||
BalanceAttributeIDs string `index:"13" re:""`
|
||||
BalanceRateProfileIDs string `index:"14" re:""`
|
||||
ThresholdIDs string `index:"15" re:""`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
|
||||
@@ -997,21 +997,16 @@ type TPAccountBalance struct {
|
||||
AttributeIDs []string
|
||||
RateProfileIDs []string
|
||||
UnitFactors []*TPBalanceUnitFactor
|
||||
Units float64
|
||||
Units string
|
||||
}
|
||||
|
||||
func NewTPBalanceCostIncrement(filtersStr, incrementStr, fixedFeeStr, recurrentFeeStr string) (costIncrement *TPBalanceCostIncrement, err error) {
|
||||
costIncrement = new(TPBalanceCostIncrement)
|
||||
costIncrement = &TPBalanceCostIncrement{
|
||||
Increment: incrementStr,
|
||||
}
|
||||
if filtersStr != EmptyString {
|
||||
costIncrement.FilterIDs = strings.Split(filtersStr, ANDSep)
|
||||
}
|
||||
if incrementStr != EmptyString {
|
||||
incr, err := strconv.ParseFloat(incrementStr, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
costIncrement.Increment = Float64Pointer(incr)
|
||||
}
|
||||
if fixedFeeStr != EmptyString {
|
||||
fixedFee, err := strconv.ParseFloat(fixedFeeStr, 64)
|
||||
if err != nil {
|
||||
@@ -1031,7 +1026,7 @@ func NewTPBalanceCostIncrement(filtersStr, incrementStr, fixedFeeStr, recurrentF
|
||||
|
||||
type TPBalanceCostIncrement struct {
|
||||
FilterIDs []string
|
||||
Increment *float64
|
||||
Increment string
|
||||
FixedFee *float64
|
||||
RecurrentFee *float64
|
||||
}
|
||||
@@ -1041,8 +1036,8 @@ func (costIncr *TPBalanceCostIncrement) AsString() (s string) {
|
||||
s = s + strings.Join(costIncr.FilterIDs, ANDSep)
|
||||
}
|
||||
s = s + InfieldSep
|
||||
if costIncr.Increment != nil {
|
||||
s = s + strconv.FormatFloat(*costIncr.Increment, 'f', -1, 64)
|
||||
if costIncr.Increment != EmptyString {
|
||||
s = s + costIncr.Increment
|
||||
}
|
||||
s = s + InfieldSep
|
||||
if costIncr.FixedFee != nil {
|
||||
|
||||
Reference in New Issue
Block a user