mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
EventCost BalanceChargeUUID -> AccountingUUID
This commit is contained in:
@@ -59,7 +59,7 @@ func NewEventCostFromCallCost(cc *CallCost, cgrID, runID string) (ec *EventCost)
|
||||
if incr.BalanceInfo == nil {
|
||||
continue
|
||||
}
|
||||
//BalanceChargeUUID
|
||||
//AccountingUUID
|
||||
if incr.BalanceInfo.Unit != nil {
|
||||
// 2 balances work-around
|
||||
ecUUID := utils.META_NONE // populate no matter what due to Unit not nil
|
||||
@@ -74,7 +74,7 @@ func NewEventCostFromCallCost(cc *CallCost, cgrID, runID string) (ec *EventCost)
|
||||
ecUUID = uuid
|
||||
}
|
||||
}
|
||||
cIt.BalanceChargeUUID = ec.Accounting.GetUUIDWithSet(
|
||||
cIt.AccountingUUID = ec.Accounting.GetUUIDWithSet(
|
||||
&BalanceCharge{
|
||||
AccountID: incr.BalanceInfo.AccountID,
|
||||
BalanceUUID: incr.BalanceInfo.Unit.UUID,
|
||||
@@ -82,7 +82,7 @@ func NewEventCostFromCallCost(cc *CallCost, cgrID, runID string) (ec *EventCost)
|
||||
RatingUUID: ec.ratingUUIDForRateInterval(incr.BalanceInfo.Unit.RateInterval, rf),
|
||||
ExtraChargeUUID: ecUUID})
|
||||
} else if incr.BalanceInfo.Monetary != nil { // Only monetary
|
||||
cIt.BalanceChargeUUID = ec.Accounting.GetUUIDWithSet(
|
||||
cIt.AccountingUUID = ec.Accounting.GetUUIDWithSet(
|
||||
&BalanceCharge{
|
||||
AccountID: incr.BalanceInfo.AccountID,
|
||||
BalanceUUID: incr.BalanceInfo.Monetary.UUID,
|
||||
@@ -278,8 +278,8 @@ func (ec *EventCost) AsCallCost() *CallCost {
|
||||
}
|
||||
for j, cInc := range cIl.Increments {
|
||||
incr := &Increment{Duration: cInc.Usage, Cost: cInc.Cost, CompressFactor: cInc.CompressFactor}
|
||||
if cInc.BalanceChargeUUID != "" {
|
||||
cBC := ec.Accounting[cInc.BalanceChargeUUID]
|
||||
if cInc.AccountingUUID != "" {
|
||||
cBC := ec.Accounting[cInc.AccountingUUID]
|
||||
incr.BalanceInfo = &DebitInfo{AccountID: cBC.AccountID}
|
||||
if cBC.ExtraChargeUUID != "" { // have both monetary and data
|
||||
// Work around, enforce logic with 2 balances for *voice/*monetary combination
|
||||
@@ -315,11 +315,11 @@ func (ec *EventCost) ratingGetUUIDFomEventCost(oEC *EventCost, oRatingUUID strin
|
||||
}
|
||||
|
||||
// accountingGetUUIDFromEventCost retrieves UUID based on data from another EventCost
|
||||
func (ec *EventCost) accountingGetUUIDFromEventCost(oEC *EventCost, oBalanceChargeUUID string) string {
|
||||
if oBalanceChargeUUID == "" || oBalanceChargeUUID == utils.META_NONE {
|
||||
func (ec *EventCost) accountingGetUUIDFromEventCost(oEC *EventCost, oAccountingUUID string) string {
|
||||
if oAccountingUUID == "" || oAccountingUUID == utils.META_NONE {
|
||||
return ""
|
||||
}
|
||||
oBC := oEC.Accounting[oBalanceChargeUUID].Clone()
|
||||
oBC := oEC.Accounting[oAccountingUUID].Clone()
|
||||
oBC.RatingUUID = ec.ratingGetUUIDFomEventCost(oEC, oBC.RatingUUID)
|
||||
oBC.ExtraChargeUUID = ec.accountingGetUUIDFromEventCost(oEC, oBC.ExtraChargeUUID)
|
||||
return ec.Accounting.GetUUIDWithSet(oBC)
|
||||
@@ -330,7 +330,7 @@ func (ec *EventCost) appendCIlFromEC(oEC *EventCost, cIlIdx int) {
|
||||
cIl := oEC.Charges[cIlIdx]
|
||||
cIl.RatingUUID = ec.ratingGetUUIDFomEventCost(oEC, cIl.RatingUUID)
|
||||
for _, cIt := range cIl.Increments {
|
||||
cIt.BalanceChargeUUID = ec.accountingGetUUIDFromEventCost(oEC, cIt.BalanceChargeUUID)
|
||||
cIt.AccountingUUID = ec.accountingGetUUIDFromEventCost(oEC, cIt.AccountingUUID)
|
||||
}
|
||||
ec.Charges = append(ec.Charges, cIl)
|
||||
}
|
||||
@@ -383,7 +383,7 @@ func (ec *EventCost) RemoveStaleReferences() {
|
||||
var keyUsed bool
|
||||
for _, cIl := range ec.Charges {
|
||||
for _, cIt := range cIl.Increments {
|
||||
if cIt.BalanceChargeUUID == key {
|
||||
if cIt.AccountingUUID == key {
|
||||
keyUsed = true
|
||||
break
|
||||
}
|
||||
@@ -583,7 +583,7 @@ func (ec *EventCost) Trim(atUsage time.Duration) (srplusEC *EventCost, err error
|
||||
for _, cIl := range srplusEC.Charges {
|
||||
cIl.RatingUUID = srplusEC.ratingGetUUIDFomEventCost(ec, cIl.RatingUUID)
|
||||
for _, incr := range cIl.Increments {
|
||||
incr.BalanceChargeUUID = srplusEC.accountingGetUUIDFromEventCost(ec, incr.BalanceChargeUUID)
|
||||
incr.AccountingUUID = srplusEC.accountingGetUUIDFromEventCost(ec, incr.AccountingUUID)
|
||||
}
|
||||
}
|
||||
ec.RemoveStaleReferences() // data should be transfered by now, can clean the old one
|
||||
|
||||
@@ -35,28 +35,28 @@ var testEC = &EventCost{
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
BalanceChargeUUID: "9bdad10",
|
||||
CompressFactor: 1,
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
AccountingUUID: "9bdad10",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
BalanceChargeUUID: "3455b83",
|
||||
CompressFactor: 10,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
AccountingUUID: "3455b83",
|
||||
CompressFactor: 10,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(10 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 2,
|
||||
Usage: time.Duration(10 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 2,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
BalanceChargeUUID: "44d6c02",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingUUID: "44d6c02",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -65,10 +65,10 @@ var testEC = &EventCost{
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 4,
|
||||
@@ -399,22 +399,22 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
RatingUUID: "f2518464-68b8-42f4-acec-aef23d714314",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
BalanceChargeUUID: "44e97dec-8a7e-43d0-8b0a-736d46b5613e",
|
||||
CompressFactor: 1,
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
AccountingUUID: "44e97dec-8a7e-43d0-8b0a-736d46b5613e",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
BalanceChargeUUID: "a555cde8-4bd0-408a-afbc-c3ba64888927",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
AccountingUUID: "a555cde8-4bd0-408a-afbc-c3ba64888927",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
BalanceChargeUUID: "906bfd0f-035c-40a3-93a8-46f71627983e",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingUUID: "906bfd0f-035c-40a3-93a8-46f71627983e",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -426,10 +426,10 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
RatingUUID: "f2518464-68b8-42f4-acec-aef23d714314",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "c890a899-df43-497a-9979-38492713f57b",
|
||||
CompressFactor: 60,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "c890a899-df43-497a-9979-38492713f57b",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -580,17 +580,17 @@ func TestNewEventCostFromCallCost(t *testing.T) {
|
||||
}
|
||||
// Compare to original timestamp
|
||||
if !reflect.DeepEqual(cc.Timespans[0].Increments[2].BalanceInfo.Unit.RateInterval.Rating.Rates,
|
||||
ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID]) {
|
||||
ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID]) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(cc.Timespans[0].Increments[2].BalanceInfo.Unit.RateInterval.Rating.Rates),
|
||||
utils.ToJSON(ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID]))
|
||||
utils.ToJSON(ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID]))
|
||||
}
|
||||
// Compare to expected EC
|
||||
if !reflect.DeepEqual(eEC.Rates[eEC.Rating[eEC.Accounting[eEC.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID],
|
||||
ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID]) {
|
||||
if !reflect.DeepEqual(eEC.Rates[eEC.Rating[eEC.Accounting[eEC.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID],
|
||||
ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID]) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eEC.Rates[eEC.Rating[eEC.Accounting[eEC.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID]),
|
||||
utils.ToJSON(ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].BalanceChargeUUID].RatingUUID].RatesUUID]))
|
||||
utils.ToJSON(eEC.Rates[eEC.Rating[eEC.Accounting[eEC.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID]),
|
||||
utils.ToJSON(ec.Rates[ec.Rating[ec.Accounting[ec.Charges[0].Increments[2].AccountingUUID].RatingUUID].RatesUUID]))
|
||||
}
|
||||
if len(ec.Accounting) != len(eEC.Accounting) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eEC, ec)
|
||||
@@ -640,22 +640,22 @@ func TestECAsCallCost(t *testing.T) {
|
||||
RatingUUID: "f2518464-68b8-42f4-acec-aef23d714314",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
BalanceChargeUUID: "44e97dec-8a7e-43d0-8b0a-736d46b5613e",
|
||||
CompressFactor: 1,
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
AccountingUUID: "44e97dec-8a7e-43d0-8b0a-736d46b5613e",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
BalanceChargeUUID: "a555cde8-4bd0-408a-afbc-c3ba64888927",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
AccountingUUID: "a555cde8-4bd0-408a-afbc-c3ba64888927",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
BalanceChargeUUID: "906bfd0f-035c-40a3-93a8-46f71627983e",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingUUID: "906bfd0f-035c-40a3-93a8-46f71627983e",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -664,10 +664,10 @@ func TestECAsCallCost(t *testing.T) {
|
||||
RatingUUID: "f2518464-68b8-42f4-acec-aef23d714314",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "c890a899-df43-497a-9979-38492713f57b",
|
||||
CompressFactor: 60,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "c890a899-df43-497a-9979-38492713f57b",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -929,28 +929,28 @@ func TestECTrimMiddle1(t *testing.T) {
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
BalanceChargeUUID: "9bdad10",
|
||||
CompressFactor: 1,
|
||||
Usage: time.Duration(0),
|
||||
Cost: 0.1,
|
||||
AccountingUUID: "9bdad10",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
BalanceChargeUUID: "3455b83",
|
||||
CompressFactor: 10,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0,
|
||||
AccountingUUID: "3455b83",
|
||||
CompressFactor: 10,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(10 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 2,
|
||||
Usage: time.Duration(10 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 2,
|
||||
},
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
BalanceChargeUUID: "44d6c02",
|
||||
CompressFactor: 30,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.005,
|
||||
AccountingUUID: "44d6c02",
|
||||
CompressFactor: 30,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -959,10 +959,10 @@ func TestECTrimMiddle1(t *testing.T) {
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 2,
|
||||
@@ -971,10 +971,10 @@ func TestECTrimMiddle1(t *testing.T) {
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 10,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 10,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -986,10 +986,10 @@ func TestECTrimMiddle1(t *testing.T) {
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 50,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 50,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
@@ -998,10 +998,10 @@ func TestECTrimMiddle1(t *testing.T) {
|
||||
RatingUUID: "c1a5ab9",
|
||||
Increments: []*ChargingIncrement{
|
||||
&ChargingIncrement{
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
BalanceChargeUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
Usage: time.Duration(1 * time.Second),
|
||||
Cost: 0.01,
|
||||
AccountingUUID: "a012888",
|
||||
CompressFactor: 60,
|
||||
},
|
||||
},
|
||||
CompressFactor: 1,
|
||||
|
||||
@@ -123,16 +123,16 @@ func (cIl *ChargingInterval) Clone() (cln *ChargingInterval) {
|
||||
|
||||
// ChargingIncrement represents one unit charged inside an interval
|
||||
type ChargingIncrement struct {
|
||||
Usage time.Duration
|
||||
Cost float64
|
||||
BalanceChargeUUID string
|
||||
CompressFactor int
|
||||
Usage time.Duration
|
||||
Cost float64
|
||||
AccountingUUID string
|
||||
CompressFactor int
|
||||
}
|
||||
|
||||
func (cIt *ChargingIncrement) Equals(oCIt *ChargingIncrement) bool {
|
||||
return cIt.Usage == oCIt.Usage &&
|
||||
cIt.Cost == oCIt.Cost &&
|
||||
cIt.BalanceChargeUUID == oCIt.BalanceChargeUUID &&
|
||||
cIt.AccountingUUID == oCIt.AccountingUUID &&
|
||||
cIt.CompressFactor == oCIt.CompressFactor
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,6 @@ func (self *SMGSession) close(usage time.Duration) (err error) {
|
||||
// Attempts to refund a duration, error on failure
|
||||
// usage represents the real usage
|
||||
func (self *SMGSession) refund(usage time.Duration) (err error) {
|
||||
utils.Logger.Debug(fmt.Sprintf("### refund, usage: %v", usage))
|
||||
if self.EventCost == nil {
|
||||
return
|
||||
}
|
||||
@@ -207,6 +206,7 @@ func (self *SMGSession) refund(usage time.Duration) (err error) {
|
||||
}
|
||||
|
||||
cc := srplsEC.AsCallCost()
|
||||
utils.Logger.Debug(fmt.Sprintf("### cc: %s", utils.ToJSON(cc)))
|
||||
var incrmts engine.Increments
|
||||
for _, tmspn := range cc.Timespans {
|
||||
for _, incr := range tmspn.Increments {
|
||||
|
||||
Reference in New Issue
Block a user