Added NewFreeEventCost function

This commit is contained in:
Trial97
2021-02-11 17:22:16 +02:00
committed by Dan Christian Bogos
parent c14a039304
commit a2688b9536
5 changed files with 89 additions and 26 deletions

View File

@@ -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 ]

View File

@@ -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.

View File

@@ -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{},
}
}

View File

@@ -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 {

View File

@@ -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",