diff --git a/docs/tariff_plans.rst b/docs/tariff_plans.rst index 9bed8cc73..8c9344837 100644 --- a/docs/tariff_plans.rst +++ b/docs/tariff_plans.rst @@ -300,3 +300,49 @@ MinutesWeight This field is used only if the balanceTag is MINUTES. If more minute balances are suitable for a call the one with smaller weight will be used first. Weight If there are multiple actions in a group, they will be executed in the order of their weight (smaller first). + +4.2.10. Derived Chargers +~~~~~~~~~~~~~~~~~~~~~~~~~ + +For each call we can bill more than one time, for that we need to use the +following options: + ++-----------+-------------+----------+---------+---------+--------------+-----------+--------------+----------------+-------------+---------------+--------------+--------------+------------------+----------------+-----------------+------------+ +| Direction | Tenant | Category | Account | Subject | RunId | RunFilter | ReqTypeField | DirectionField | TenantField | CategoryField | AccountField | SubjectField | DestinationField | SetupTimeField | AnswerTimeField | UsageField | ++===========+=============+==========+=========+=========+==============+===========+==============+================+=============+===============+==============+==============+==================+================+=================+============+ +| \*out | cgrates.org | call | 1001 | 1001 | derived_run1 | | ^rated | \*default | \*default | \*default | \*default | ^1002 | \*default | \*default | \*default | \*default | ++-----------+-------------+----------+---------+---------+--------------+-----------+--------------+----------------+-------------+---------------+--------------+--------------+------------------+----------------+-----------------+------------+ + + +In derived charges we have 2 different kind of options, filters, and actions: + +Filters: With the following fields we filter the calls that need to run a extra +billing parameter. + + Direction + + Tenant + + Category + + Account + + Subject + +Actions: In case of the filter options match, platform creates extra runid with +the fields that we want to modify. + + + RunId + + RunFilter + + ReqTypeField + + DirectionField + + TenantField + + CategoryField + + AccountField + + SubjectField + + DestinationField + + SetupTimeField + + AnswerTimeField + + UsageField + +In the example, all the calls with direction=out, tenant=cgrates.org, +category="call" and account and subject equal 1001. Will be created a new cdr in +the table *rated_cdrs* with the runID derived_run1, and the subject 1002. + +This feature it's useful in the case that you want to rated the calls 2 times, +for example rated for different tenants or resellers. diff --git a/engine/account.go b/engine/account.go index 2b52cfead..fcb2a70c0 100644 --- a/engine/account.go +++ b/engine/account.go @@ -129,13 +129,15 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error { a.Balance.Value = -a.Balance.Value a.Balance.dirty = true // Mark the balance as dirty since we have modified and it should be checked by action triggers ub.BalanceMap[id] = append(ub.BalanceMap[id], a.Balance) - if a.Balance.SharedGroup != "" { - // add shared group member - sg, err := accountingStorage.GetSharedGroup(a.Balance.SharedGroup, false) - if err != nil || sg == nil { - //than problem - Logger.Warning(fmt.Sprintf("Could not get shared group: %v", a.Balance.SharedGroup)) - } else { + } + if a.Balance.SharedGroup != "" { + // add shared group member + sg, err := accountingStorage.GetSharedGroup(a.Balance.SharedGroup, false) + if err != nil || sg == nil { + //than problem + Logger.Warning(fmt.Sprintf("Could not get shared group: %v", a.Balance.SharedGroup)) + } else { + if !utils.IsSliceMember(sg.MemberIds, ub.Id) { // add member and save sg.MemberIds = append(sg.MemberIds, ub.Id) accountingStorage.SetSharedGroup(sg)