[freeside-commits] branch master updated. e204d78f913905bcbf46ad5e664443f183875e8e

Mark Wells mark at 420.am
Tue Aug 16 20:56:32 PDT 2016


The branch, master has been updated
       via  e204d78f913905bcbf46ad5e664443f183875e8e (commit)
      from  8f37f0b3f6a946839132120984ec62b6f7ad7594 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e204d78f913905bcbf46ad5e664443f183875e8e
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Aug 16 20:56:07 2016 -0700

    respect granularity settings for display of inbound call duration, #71715

diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 6e5637c..29f1b31 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -5613,6 +5613,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 d3d62e0..155090d 100644
--- a/FS/FS/cdr.pm
+++ b/FS/FS/cdr.pm
@@ -507,8 +507,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 0209f0d..3c1f453 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 d032100..78517dd 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<cdr_termination>
+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<phonenum> 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 81f2765..e911439 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);

-----------------------------------------------------------------------

Summary of changes:
 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(-)




More information about the freeside-commits mailing list