From a2688b9536335f90a75b64e9193a86542791531e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 11 Feb 2021 17:22:16 +0200 Subject: [PATCH] Added NewFreeEventCost function --- .drone.yml | 7 ++--- engine/callcost.go | 21 ++++++++----- engine/libeventcost.go | 60 ++++++++++++++++++++++++++++++++++++++ engine/timespans.go | 25 ++++++++-------- engine/z_onstor_it_test.go | 2 +- 5 files changed, 89 insertions(+), 26 deletions(-) diff --git a/.drone.yml b/.drone.yml index 675627609..7b611e7af 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,9 +21,8 @@ steps: from_secret: credentials token: from_secret: token - recipients: - - alexandru.tripon@itsyscom.com - + when: + status: [ changed, failure ] --- @@ -51,8 +50,6 @@ steps: from_secret: credentials token: from_secret: token - recipients: - - alexandru.tripon@itsyscom.com when: status: [ changed, failure ] diff --git a/engine/callcost.go b/engine/callcost.go index c6f831b7f..f87b36cac 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -27,14 +27,19 @@ import ( // The output structure that will be returned with the call cost information. type CallCost struct { - Category, Tenant, Subject, Account, Destination, ToR string - Cost float64 - Timespans TimeSpans - RatedUsage float64 - AccountSummary *AccountSummary - deductConnectFee bool - negativeConnectFee bool // the connect fee went negative on default balance - maxCostDisconect bool + Category string + Tenant string + Subject string + Account string + Destination string + ToR string + Cost float64 + Timespans TimeSpans + RatedUsage float64 + AccountSummary *AccountSummary + deductConnectFee bool + negativeConnectFee bool // the connect fee went negative on default balance + maxCostDisconect bool } // Merges the received timespan if they are similar (same activation period, same interval, same minute info. diff --git a/engine/libeventcost.go b/engine/libeventcost.go index 8ae0d59e1..218947376 100644 --- a/engine/libeventcost.go +++ b/engine/libeventcost.go @@ -623,3 +623,63 @@ func IfaceAsEventCost(itm interface{}) (ec *EventCost, err error) { } return } + +// NewFreeEventCost returns an EventCost of given duration that it's free +func NewFreeEventCost(cgrID, runID, account string, tStart time.Time, usage time.Duration) *EventCost { + return &EventCost{ + CGRID: cgrID, + RunID: runID, + StartTime: tStart, + Cost: utils.Float64Pointer(0), + Charges: []*ChargingInterval{{ + RatingID: "*free", + Increments: []*ChargingIncrement{ + { + Usage: usage, + AccountingID: "*free", + CompressFactor: 1, + }, + }, + CompressFactor: 1, + }}, + + Rating: Rating{ + "*free": { + RoundingMethod: "*up", + RoundingDecimals: 5, + RatesID: "*free", + RatingFiltersID: "*free", + TimingID: "*free", + }, + }, + Accounting: Accounting{ + "*free": { + AccountID: account, + // BalanceUUID: "", + RatingID: "*free", + }, + }, + RatingFilters: RatingFilters{ + "*free": { + utils.Subject: "", + utils.DestinationPrefixName: "", + utils.DestinationID: "", + utils.RatingPlanID: "", + }, + }, + Rates: ChargedRates{ + "*free": { + { + RateIncrement: usage, + RateUnit: usage, + }, + }, + }, + Timings: ChargedTimings{ + "*free": { + StartTime: "00:00:00", + }, + }, + cache: utils.MapStorage{}, + } +} diff --git a/engine/timespans.go b/engine/timespans.go index 6869a13ef..9ec286f57 100644 --- a/engine/timespans.go +++ b/engine/timespans.go @@ -31,18 +31,19 @@ import ( A unit in which a call will be split that has a specific price related interval attached to it. */ type TimeSpan struct { - TimeStart, TimeEnd time.Time - Cost float64 - RateInterval *RateInterval - DurationIndex time.Duration // the call duration so far till TimeEnd - Increments Increments - RoundIncrement *Increment - MatchedSubject string - MatchedPrefix string - MatchedDestId string - RatingPlanId string - CompressFactor int - ratingInfo *RatingInfo + TimeStart time.Time + TimeEnd time.Time + Cost float64 + RateInterval *RateInterval + DurationIndex time.Duration // the call duration so far till TimeEnd + Increments Increments + RoundIncrement *Increment + MatchedSubject string + MatchedPrefix string + MatchedDestId string + RatingPlanId string + CompressFactor int + ratingInfo *RatingInfo } type Increment struct { diff --git a/engine/z_onstor_it_test.go b/engine/z_onstor_it_test.go index af5f28236..7eef0df6b 100644 --- a/engine/z_onstor_it_test.go +++ b/engine/z_onstor_it_test.go @@ -2323,7 +2323,7 @@ func testOnStorITAccountProfile(t *testing.T) { }, Type: utils.MetaVoice, Units: &utils.Decimal{ - new(decimal.Big).SetUint64(10), + Big: new(decimal.Big).SetUint64(10), }, Opts: map[string]interface{}{ "key1": "val1",