From a846aefc07208e8c4c0b0f223b90918828ce2bb4 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 16 Aug 2016 20:56:07 -0700 Subject: [PATCH] respect granularity settings for display of inbound call duration, #71715 --- FS/FS/Schema.pm | 1 + FS/FS/cdr.pm | 5 +++-- FS/FS/cdr_termination.pm | 9 +++++++++ FS/FS/detail_format.pm | 17 ++++++++++------- FS/FS/part_pkg/voip_inbound.pm | 9 +++------ 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index a49566772..fef0ec718 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -3933,6 +3933,7 @@ sub tables_hashref { 'rated_price', 'decimal', 'NULL', '10,4', '', '', 'rated_seconds', 'int', 'NULL', '', '', '', 'rated_minutes', 'double precision', 'NULL', '', '', '', + 'rated_granularity','int', 'NULL', '', '', '', 'status', 'varchar', 'NULL', 32, '', '', 'svcnum', 'int', 'NULL', '', '', '', ], diff --git a/FS/FS/cdr.pm b/FS/FS/cdr.pm index a2b9a8ccb..4d4c767f0 100644 --- a/FS/FS/cdr.pm +++ b/FS/FS/cdr.pm @@ -495,8 +495,9 @@ sub set_status_and_rated_price { rated_price => $rated_price, status => $status, }); - $term->rated_seconds($opt{rated_seconds}) if exists($opt{rated_seconds}); - $term->rated_minutes($opt{rated_minutes}) if exists($opt{rated_minutes}); + foreach (qw(rated_seconds rated_minutes rated_granularity)) { + $term->set($_, $opt{$_}) if exists($opt{$_}); + } $term->svcnum($svcnum) if $svcnum; return $term->insert; diff --git a/FS/FS/cdr_termination.pm b/FS/FS/cdr_termination.pm index 0209f0d0c..3c1f453d8 100644 --- a/FS/FS/cdr_termination.pm +++ b/FS/FS/cdr_termination.pm @@ -47,6 +47,12 @@ termpart rated_price +=item rated_seconds + +=item rated_minutes + +=item rated_granularity + =item status status @@ -120,6 +126,9 @@ sub check { #|| $self->ut_foreign_key('termpart', 'part_termination', 'termpart') || $self->ut_number('termpart') || $self->ut_floatn('rated_price') + || $self->ut_numbern('rated_seconds') + || $self->ut_floatn('rated_minutes') + || $self->ut_numbern('rated_granularity') || $self->ut_enum('status', [ '', 'processing-tiered', 'done' ] ) # , 'skipped' ] ) ; return $error if $error; diff --git a/FS/FS/detail_format.pm b/FS/FS/detail_format.pm index d032100b3..78517dd5b 100644 --- a/FS/FS/detail_format.pm +++ b/FS/FS/detail_format.pm @@ -186,6 +186,11 @@ rated_regionname => regionname accountcode => accountcode startdate => startdate +If the formatter is in inbound mode, it will look up a C +record and use rated_price and rated_seconds from that, and acctid will be +set to null to avoid linking the CDR to the detail record for the inbound +leg of the call. + 'phonenum' is set to the internal C value set on the formatter object. @@ -209,10 +214,10 @@ sub single_detail { $price = 0 if $cdr->freesidestatus eq 'no-charge'; FS::cust_bill_pkg_detail->new( { - 'acctid' => $cdr->acctid, + 'acctid' => ($self->{inbound} ? '' : $cdr->acctid), 'amount' => $price, 'classnum' => $cdr->rated_classnum, - 'duration' => $cdr->rated_seconds, + 'duration' => $object->rated_seconds, 'regionname' => $cdr->rated_regionname, 'accountcode' => $cdr->accountcode, 'startdate' => $cdr->startdate, @@ -280,13 +285,11 @@ sub duration { my $object = $self->{inbound} ? $cdr->cdr_termination(1) : $cdr; my $sec = $object->rated_seconds if $object; $sec ||= 0; - # XXX termination objects don't have rated_granularity so this may - # result in inbound CDRs being displayed as min/sec when they shouldn't. - # Should probably fix this. - if ( $cdr->rated_granularity eq '0' ) { + # termination objects now have rated_granularity. + if ( $object->rated_granularity eq '0' ) { '1 call'; } - elsif ( $cdr->rated_granularity eq '60' ) { + elsif ( $object->rated_granularity eq '60' ) { sprintf('%dm', ($sec + 59)/60); } else { diff --git a/FS/FS/part_pkg/voip_inbound.pm b/FS/FS/part_pkg/voip_inbound.pm index 5bce1e123..9bf9efd88 100644 --- a/FS/FS/part_pkg/voip_inbound.pm +++ b/FS/FS/part_pkg/voip_inbound.pm @@ -292,10 +292,7 @@ sub calc_usage { my @call_details = ( $cdr->downstream_csv( 'format' => $output_format, 'charge' => $charge, - 'seconds' => ($use_duration - ? $cdr->duration - : $cdr->billsec - ), + 'seconds' => $seconds, 'granularity' => $granularity, ) ); @@ -317,10 +314,10 @@ sub calc_usage { 'done', $charge, $cust_svc->svcnum, - 'rated_seconds' => $use_duration ? $cdr->duration : $cdr->billsec, + 'rated_seconds' => $seconds, 'rated_granularity' => $granularity, 'rated_classnum' => $cdr->calltypenum, - 'inbound' => 1, + 'inbound' => 1, # to update cdr_termination, not cdr ); die $error if $error; $formatter->append($cdr); -- 2.11.0