mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added RatedUsage to call cost
This commit is contained in:
@@ -29,6 +29,7 @@ type CallCost struct {
|
||||
Direction, Category, Tenant, Subject, Account, Destination, TOR string
|
||||
Cost float64
|
||||
Timespans TimeSpans
|
||||
RatedUsage float64
|
||||
deductConnectFee bool
|
||||
negativeConnectFee bool // the connect fee went negative on default balance
|
||||
maxCostDisconect bool
|
||||
@@ -61,6 +62,12 @@ func (cc *CallCost) GetDuration() (td time.Duration) {
|
||||
return
|
||||
}
|
||||
|
||||
func (cc *CallCost) UpdateRatedUsage() time.Duration {
|
||||
totalDuration := cc.GetDuration()
|
||||
cc.RatedUsage = totalDuration.Seconds()
|
||||
return totalDuration
|
||||
}
|
||||
|
||||
func (cc *CallCost) GetConnectFee() float64 {
|
||||
if len(cc.Timespans) == 0 ||
|
||||
cc.Timespans[0].RateInterval == nil ||
|
||||
|
||||
@@ -50,6 +50,10 @@ func TestSingleResultMerge(t *testing.T) {
|
||||
if cc1.Cost != 122 {
|
||||
t.Errorf("Exdpected 120 was %v", cc1.Cost)
|
||||
}
|
||||
d := cc1.UpdateRatedUsage()
|
||||
if d != 2*time.Minute || cc1.RatedUsage != 120.0 {
|
||||
t.Errorf("error updating rating usage: %v, %v", d, cc1.RatedUsage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleResultMerge(t *testing.T) {
|
||||
|
||||
@@ -526,6 +526,7 @@ func (cd *CallDescriptor) getCost() (*CallCost, error) {
|
||||
cc.Cost = utils.Round(cc.Cost, roundingDecimals, roundingMethod)
|
||||
//utils.Logger.Info(fmt.Sprintf("<Rater> Get Cost: %s => %v", cd.GetKey(), cc))
|
||||
cc.Timespans.Compress()
|
||||
cc.UpdateRatedUsage()
|
||||
return cc, err
|
||||
}
|
||||
|
||||
@@ -668,6 +669,7 @@ func (cd *CallDescriptor) debit(account *Account, dryRun bool, goNegative bool)
|
||||
return nil, err
|
||||
}
|
||||
cc.updateCost()
|
||||
cc.UpdateRatedUsage()
|
||||
cc.Timespans.Compress()
|
||||
//log.Printf("OUT CC: ", cc)
|
||||
return
|
||||
|
||||
@@ -107,6 +107,7 @@ func (self *CdrServer) ProcessExternalCdr(eCDR *ExternalCDR) error {
|
||||
|
||||
// RPC method, used to log callcosts to db
|
||||
func (self *CdrServer) LogCallCost(ccl *CallCostLog) error {
|
||||
ccl.CallCost.UpdateRatedUsage() // make sure rated usage is updated
|
||||
if ccl.CheckDuplicate {
|
||||
_, err := self.guard.Guard(func() (interface{}, error) {
|
||||
cc, err := self.cdrDb.GetCallCostLog(ccl.CgrId, ccl.RunId)
|
||||
|
||||
Reference in New Issue
Block a user