added RatedUsage to call cost

This commit is contained in:
Radu Ioan Fericean
2016-01-20 15:59:27 +02:00
parent 2c9b09c9c6
commit 4d6be144c3
4 changed files with 14 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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