mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
AccountS - concrete balances with support for chained debitUnit
This commit is contained in:
@@ -40,9 +40,9 @@ type abstractBalance struct {
|
||||
ralsConns []string
|
||||
}
|
||||
|
||||
// debit implements the balanceOperator interface
|
||||
func (ab *abstractBalance) debit(cgrEv *utils.CGREventWithOpts,
|
||||
startTime time.Time, usage *decimal.Big) (ec *utils.EventCharges, err error) {
|
||||
// debitUsage implements the balanceOperator interface
|
||||
func (ab *abstractBalance) debitUsage(usage *decimal.Big, startTime time.Time,
|
||||
cgrEv *utils.CGREventWithOpts) (ec *utils.EventCharges, err error) {
|
||||
//var uF *utils.UsageFactor
|
||||
if _, _, err = usageWithFactor(ab.blnCfg, ab.fltrS, cgrEv, usage); err != nil {
|
||||
return
|
||||
|
||||
@@ -28,21 +28,22 @@ import (
|
||||
)
|
||||
|
||||
// newConcreteBalance constructs a concreteBalanceOperator
|
||||
func newConcreteBalanceOperator(blnCfg *utils.Balance,
|
||||
func newConcreteBalanceOperator(blnCfg *utils.Balance, cncrtBlncs []*concreteBalance,
|
||||
fltrS *engine.FilterS, ralsConns []string) balanceOperator {
|
||||
return &concreteBalance{blnCfg, fltrS, ralsConns}
|
||||
return &concreteBalance{blnCfg, cncrtBlncs, fltrS, ralsConns}
|
||||
}
|
||||
|
||||
// concreteBalance is the operator for *concrete balance type
|
||||
type concreteBalance struct {
|
||||
blnCfg *utils.Balance
|
||||
fltrS *engine.FilterS
|
||||
ralsConns []string
|
||||
blnCfg *utils.Balance
|
||||
cncrtBlncs []*concreteBalance // paying balances
|
||||
fltrS *engine.FilterS
|
||||
ralsConns []string
|
||||
}
|
||||
|
||||
// debit implements the balanceOperator interface
|
||||
func (cb *concreteBalance) debit(cgrEv *utils.CGREventWithOpts,
|
||||
startTime time.Time, usage *decimal.Big) (ec *utils.EventCharges, err error) {
|
||||
func (cb *concreteBalance) debitUsage(usage *decimal.Big, startTime time.Time,
|
||||
cgrEv *utils.CGREventWithOpts) (ec *utils.EventCharges, err error) {
|
||||
//var uF *utils.UsageFactor
|
||||
if _, _, err = usageWithFactor(cb.blnCfg, cb.fltrS, cgrEv, usage); err != nil {
|
||||
return
|
||||
|
||||
@@ -40,7 +40,7 @@ func newAccountBalances(acnt *utils.AccountProfile,
|
||||
// populate cncrtBlncs
|
||||
acntBlncs.cncrtBlncs = make([]*concreteBalance, len(acntBlncs.typIdx[utils.MetaConcrete]))
|
||||
for i, blncIdx := range acntBlncs.typIdx[utils.MetaConcrete] {
|
||||
acntBlncs.cncrtBlncs[i] = newConcreteBalanceOperator(acntBlncs.blnCfgs[blncIdx], fltrS, ralsConns).(*concreteBalance)
|
||||
acntBlncs.cncrtBlncs[i] = newConcreteBalanceOperator(acntBlncs.blnCfgs[blncIdx], acntBlncs.cncrtBlncs, fltrS, ralsConns).(*concreteBalance)
|
||||
acntBlncs.opers[acntBlncs.blnCfgs[blncIdx].ID] = acntBlncs.cncrtBlncs[i]
|
||||
}
|
||||
// populate opers
|
||||
@@ -75,7 +75,7 @@ func newBalanceOperator(blncCfg *utils.Balance, cncrtBlncs []*concreteBalance,
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported balance type: <%s>", blncCfg.Type)
|
||||
case utils.MetaConcrete:
|
||||
return newConcreteBalanceOperator(blncCfg, fltrS, ralsConns), nil
|
||||
return newConcreteBalanceOperator(blncCfg, cncrtBlncs, fltrS, ralsConns), nil
|
||||
case utils.MetaAbstract:
|
||||
return newAbstractBalanceOperator(blncCfg, cncrtBlncs, fltrS, ralsConns), nil
|
||||
}
|
||||
@@ -83,8 +83,8 @@ func newBalanceOperator(blncCfg *utils.Balance, cncrtBlncs []*concreteBalance,
|
||||
|
||||
// balanceOperator is the implementation of a balance type
|
||||
type balanceOperator interface {
|
||||
debit(cgrEv *utils.CGREventWithOpts,
|
||||
startTime time.Time, usage *decimal.Big) (ec *utils.EventCharges, err error)
|
||||
debitUsage(usage *decimal.Big, startTime time.Time,
|
||||
cgrEv *utils.CGREventWithOpts) (ec *utils.EventCharges, err error)
|
||||
}
|
||||
|
||||
// usagewithFactor returns the usage considering also factor for the debit
|
||||
|
||||
@@ -74,7 +74,6 @@ func TestCBDebitUnits(t *testing.T) {
|
||||
} else if dbted.Cmp(decimal.New(12, 1)) != 0 { // only 1.2 is possible due to increment
|
||||
//} else if dbted.Cmp(new(decimal.Big).SetFloat64(1.2)) != 0 {
|
||||
t.Errorf("debited: %s, cmp: %v", dbted, dbted.Cmp(new(decimal.Big).SetFloat64(1.2)))
|
||||
|
||||
} else if cb.blnCfg.Value != 0.05 {
|
||||
t.Errorf("balance remaining: %f", cb.blnCfg.Value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user