From 1babf3c4022d8af85c43eb589a5906997aedd289 Mon Sep 17 00:00:00 2001 From: DanB Date: Sun, 26 Sep 2021 19:37:55 +0200 Subject: [PATCH] SessionS accountSMaxAbstracts --- sessions/sessions.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sessions/sessions.go b/sessions/sessions.go index f351f8619..f76fa71cc 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1429,6 +1429,24 @@ func (sS *SessionS) chargeEvent(ctx *context.Context, cgrEv *utils.CGREvent, for return // returns here the maxUsage from update } +// accounSMaxAbstracts computes the maximum abstract units for the events provided +func (sS *SessionS) accounSMaxAbstracts(ctx *context.Context, cgrEvs []*utils.CGREvent) (maxAbstracts *utils.Decimal, err error) { + if len(sS.cgrCfg.SessionSCfg().AttrSConns) == 0 { + return nil, utils.NewErrNotConnected(utils.AccountS) + } + for _, cgrEv := range cgrEvs { + acntCost := new(utils.ExtEventCharges) + if err = sS.connMgr.Call(ctx, sS.cgrCfg.SessionSCfg().AttrSConns, // Fix Here with AccountS + utils.AccountSv1DebitAbstracts, cgrEv, &acntCost); err != nil { + return + } else if maxAbstracts == nil || + maxAbstracts.Compare(utils.NewDecimalFromFloat64(*acntCost.Abstracts)) == 1 { // should compare directly against Decimal + maxAbstracts = utils.NewDecimalFromFloat64(*acntCost.Abstracts) // did not optimize here since we need to remove floats from acntCost + } + } + return +} + // APIs start here // BiRPCv1GetActiveSessions returns the list of active sessions based on filter