mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated EventCost rounding increment handling.Fixes #3018
This commit is contained in:
@@ -308,7 +308,7 @@ func (ec *EventCost) GetCost() float64 {
|
||||
if ec.Cost == nil {
|
||||
var cost float64
|
||||
for _, ci := range ec.Charges {
|
||||
cost += ci.TotalCost()
|
||||
cost += ci.TotalCost(ec.Accounting)
|
||||
}
|
||||
cost = utils.Round(cost, globalRoundingDecimals, utils.MetaRoundingMiddle)
|
||||
ec.Cost = &cost
|
||||
@@ -408,7 +408,7 @@ func (ec *EventCost) AsCallCost(tor string) *CallCost {
|
||||
cc.Timespans = make(TimeSpans, len(ec.Charges))
|
||||
for i, cIl := range ec.Charges {
|
||||
ts := &TimeSpan{
|
||||
Cost: cIl.Cost(),
|
||||
Cost: cIl.Cost(ec.Accounting),
|
||||
DurationIndex: *cIl.Usage(),
|
||||
CompressFactor: cIl.CompressFactor,
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
Account: "dan",
|
||||
Destination: "+4986517174963",
|
||||
ToR: utils.MetaVoice,
|
||||
Cost: 0.75,
|
||||
Cost: 0.85,
|
||||
RatedUsage: 120.0,
|
||||
Timespans: TimeSpans{
|
||||
&TimeSpan{
|
||||
@@ -517,7 +517,7 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
},
|
||||
CompressFactor: 1,
|
||||
usage: utils.DurationPointer(60 * time.Second),
|
||||
cost: utils.Float64Pointer(0.15),
|
||||
cost: utils.Float64Pointer(0.25),
|
||||
ecUsageIdx: utils.DurationPointer(0),
|
||||
},
|
||||
{
|
||||
@@ -662,9 +662,9 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
eEC.Charges[i].Usage(), ec.Charges[i].Usage())
|
||||
}
|
||||
if !reflect.DeepEqual(eEC.Charges[i].Cost(), ec.Charges[i].Cost()) {
|
||||
if !reflect.DeepEqual(eEC.Charges[i].Cost(eEC.Accounting), ec.Charges[i].Cost(ec.Accounting)) {
|
||||
t.Errorf("Expecting: %f, received: %f",
|
||||
eEC.Charges[i].Cost(), ec.Charges[i].Cost())
|
||||
eEC.Charges[i].Cost(eEC.Accounting), ec.Charges[i].Cost(ec.Accounting))
|
||||
}
|
||||
if !reflect.DeepEqual(eEC.Charges[i].ecUsageIdx, ec.Charges[i].ecUsageIdx) {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
@@ -1746,7 +1746,7 @@ func TestECMergeGT(t *testing.T) {
|
||||
}
|
||||
if len(ecGT.Charges) != len(ecExpct.Charges) ||
|
||||
!reflect.DeepEqual(ecGT.Charges[0].TotalUsage(), ecExpct.Charges[0].TotalUsage()) ||
|
||||
!reflect.DeepEqual(ecGT.Charges[0].TotalCost(), ecExpct.Charges[0].TotalCost()) {
|
||||
!reflect.DeepEqual(ecGT.Charges[0].TotalCost(ecGT.Accounting), ecExpct.Charges[0].TotalCost(ecExpct.Accounting)) {
|
||||
t.Errorf("expecting: %s\n\n, received: %s",
|
||||
utils.ToJSON(ecExpct), utils.ToJSON(ecGT))
|
||||
}
|
||||
@@ -4222,7 +4222,7 @@ func TestECAsCallCost4(t *testing.T) {
|
||||
ToR: utils.MetaVoice,
|
||||
Timespans: TimeSpans{
|
||||
{
|
||||
Cost: 25,
|
||||
Cost: 0,
|
||||
DurationIndex: 250,
|
||||
Increments: Increments{
|
||||
{
|
||||
|
||||
@@ -94,11 +94,14 @@ func (cIl *ChargingInterval) EndTime(cIlST time.Time) (et time.Time) {
|
||||
}
|
||||
|
||||
// Cost computes the total cost on this ChargingInterval
|
||||
func (cIl *ChargingInterval) Cost() float64 {
|
||||
func (cIl *ChargingInterval) Cost(ac Accounting) float64 {
|
||||
if cIl.cost == nil {
|
||||
var cost float64
|
||||
for _, incr := range cIl.Increments {
|
||||
cost += incr.Cost * float64(incr.CompressFactor)
|
||||
if ac[incr.AccountingID] == nil || // ignore the rounding increment
|
||||
ac[incr.AccountingID].RatingID != utils.MetaRounding { // only used to justify the diference between the debited price and the final CDR cost
|
||||
cost += incr.Cost * float64(incr.CompressFactor)
|
||||
}
|
||||
}
|
||||
cost = utils.Round(cost, globalRoundingDecimals, utils.MetaRoundingMiddle)
|
||||
cIl.cost = &cost
|
||||
@@ -107,8 +110,8 @@ func (cIl *ChargingInterval) Cost() float64 {
|
||||
}
|
||||
|
||||
// TotalCost returns the cost of charges
|
||||
func (cIl *ChargingInterval) TotalCost() float64 {
|
||||
return utils.Round((cIl.Cost() * float64(cIl.CompressFactor)),
|
||||
func (cIl *ChargingInterval) TotalCost(ac Accounting) float64 {
|
||||
return utils.Round((cIl.Cost(ac) * float64(cIl.CompressFactor)),
|
||||
globalRoundingDecimals, utils.MetaRoundingMiddle)
|
||||
}
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ func TestChargingIntervalCost(t *testing.T) {
|
||||
},
|
||||
CompressFactor: 3,
|
||||
}
|
||||
tCi1 := ci1.Cost()
|
||||
tCi1 := ci1.Cost(Accounting{"Acc1": {}})
|
||||
eTCi1 := 10.84
|
||||
if tCi1 != eTCi1 {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eTCi1, tCi1)
|
||||
@@ -298,7 +298,7 @@ func TestChargingIntervalTotalCost(t *testing.T) {
|
||||
},
|
||||
CompressFactor: 3,
|
||||
}
|
||||
tCi1 := ci1.TotalCost()
|
||||
tCi1 := ci1.TotalCost(Accounting{"Acc1": {}})
|
||||
eTCi1 := 32.52
|
||||
if tCi1 != eTCi1 {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eTCi1, tCi1)
|
||||
|
||||
@@ -928,8 +928,8 @@ func testSessionsVoiceSessionTTL(t *testing.T) {
|
||||
if cdrs[0].Usage != "2m30.05s" {
|
||||
t.Errorf("Unexpected CDR Usage received, cdr: %v %+v ", cdrs[0].Usage, cdrs[0])
|
||||
}
|
||||
if cdrs[0].Cost != 1.5332 {
|
||||
t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, cdrs[0])
|
||||
if cdrs[0].Cost != 1.5333 {
|
||||
t.Errorf("Unexpected CDR Cost received, cdr: %v %+v ", cdrs[0].Cost, utils.ToJSON(cdrs[0]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user