mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 15:48:44 +05:00
fix for zero duration calldescriptors
This commit is contained in:
@@ -405,6 +405,10 @@ func (cd *CallDescriptor) GetDuration() time.Duration {
|
||||
Creates a CallCost structure with the cost information calculated for the received CallDescriptor.
|
||||
*/
|
||||
func (cd *CallDescriptor) GetCost() (*CallCost, error) {
|
||||
// check for 0 duration
|
||||
if cd.TimeEnd.Sub(cd.TimeStart) == 0 {
|
||||
return cd.CreateCallCost(), nil
|
||||
}
|
||||
if cd.DurationIndex < cd.TimeEnd.Sub(cd.TimeStart) {
|
||||
cd.DurationIndex = cd.TimeEnd.Sub(cd.TimeStart)
|
||||
}
|
||||
@@ -429,18 +433,10 @@ func (cd *CallDescriptor) GetCost() (*CallCost, error) {
|
||||
cost += ts.getCost()
|
||||
}
|
||||
//startIndex := len(fmt.Sprintf("%s:%s:%s:", cd.Direction, cd.Tenant, cd.Category))
|
||||
cc := &CallCost{
|
||||
Direction: cd.Direction,
|
||||
Category: cd.Category,
|
||||
Tenant: cd.Tenant,
|
||||
Account: cd.Account,
|
||||
Destination: cd.Destination,
|
||||
Subject: cd.Subject,
|
||||
Cost: cost,
|
||||
Timespans: timespans,
|
||||
deductConnectFee: cd.LoopIndex == 0,
|
||||
TOR: cd.TOR,
|
||||
}
|
||||
cc := cd.CreateCallCost()
|
||||
cc.Cost = cost
|
||||
cc.Timespans = timespans
|
||||
|
||||
// global rounding
|
||||
roundingDecimals, roundingMethod := cc.GetLongestRounding()
|
||||
cc.Cost = utils.Round(cc.Cost, roundingDecimals, roundingMethod)
|
||||
@@ -526,6 +522,9 @@ func (cd *CallDescriptor) GetMaxSessionDuration() (duration time.Duration, err e
|
||||
// Interface method used to add/substract an amount of cents or bonus seconds (as returned by GetCost method)
|
||||
// from user's money balance.
|
||||
func (cd *CallDescriptor) debit(account *Account, dryRun bool, goNegative bool) (cc *CallCost, err error) {
|
||||
if cd.TimeEnd.Sub(cd.TimeStart) == 0 {
|
||||
return cd.CreateCallCost(), nil
|
||||
}
|
||||
if !dryRun {
|
||||
defer accountingStorage.SetAccount(account)
|
||||
}
|
||||
|
||||
@@ -229,6 +229,17 @@ func TestGetCost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCostZero(t *testing.T) {
|
||||
t1 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 2, 17, 30, 0, 0, time.UTC)
|
||||
cd := &CallDescriptor{Direction: "*out", Category: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2, LoopIndex: 0}
|
||||
result, _ := cd.GetCost()
|
||||
expected := &CallCost{Tenant: "vdf", Subject: "rif", Destination: "0256", Cost: 0}
|
||||
if result.Cost != expected.Cost || result.GetConnectFee() != 0 {
|
||||
t.Errorf("Expected %v was %v", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCostTimespans(t *testing.T) {
|
||||
t1 := time.Date(2013, time.October, 8, 9, 23, 2, 0, time.UTC)
|
||||
t2 := time.Date(2013, time.October, 8, 9, 24, 27, 0, time.UTC)
|
||||
|
||||
Reference in New Issue
Block a user