[freeside-commits] branch FREESIDE_3_BRANCH updated. 37c23aa0e64e44c82c1ee377e756b301a8fde7bd

Mark Wells mark at 420.am
Wed Oct 22 11:57:41 PDT 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  37c23aa0e64e44c82c1ee377e756b301a8fde7bd (commit)
       via  74ed0dad3168f94cefc7cd24db9a19ea627c3a62 (commit)
      from  8b8d90fca954f44a17e85e6a53acd7dd7bda8b5b (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 37c23aa0e64e44c82c1ee377e756b301a8fde7bd
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Oct 22 11:56:56 2014 -0700

    make NENA2 export more lenient about street addresses, #14049

diff --git a/FS/FS/part_export/nena2.pm b/FS/FS/part_export/nena2.pm
index 8d59425..36f0293 100644
--- a/FS/FS/part_export/nena2.pm
+++ b/FS/FS/part_export/nena2.pm
@@ -237,27 +237,61 @@ sub data {
   $hash{calling_number} = $2;
 
   # street address
+  # some cleanup:
+  my $full_address = $cust_location->address1;
+  my $address2 = $cust_location->address2;
+  if (length($address2)) {
+    # correct 'Sp', 'Sp.', 'sp ', etc. to the word SPACE for convenience
+    $address2 =~ s/^sp\b\.? ?/SPACE /i;
+    # and join it to $full_address with a space, not a comma
+    $full_address .= ' ' . $address2;
+  }
+
   my $location_hash = Geo::StreetAddress::US->parse_address(
-    uc( join(', ', $cust_location->address1,
-                   $cust_location->address2,
-                   $cust_location->city,
-                   $cust_location->state,
-                   $cust_location->zip
+    uc( join(', ',  $full_address,
+                    $cust_location->city,
+                    $cust_location->state,
+                    $cust_location->zip
     ) )
   );
-  $hash{house_number}         = $location_hash->{number};
-  $hash{house_number_suffix}  = ''; # we don't support this, do we?
-  $hash{prefix_directional}   = $location_hash->{prefix};
-  $hash{street_name}          = $location_hash->{street};
-  $hash{street_suffix}        = $location_hash->{type};
-  $hash{post_directional}     = $location_hash->{suffix};
-  $hash{community_name}       = $location_hash->{city};
-  $hash{state}                = $location_hash->{state};
-  if ($location_hash->{sec_unit_type}) {
-    $hash{location} = $location_hash->{sec_unit_type} . ' ' .
-                      $location_hash->{sec_unit_num};
+  if ( !$location_hash and length($address2) ) {
+    # then parsing failed. Try again without the address2.
+    $location_hash = Geo::StreetAddress::US->parse_address(
+      uc( join(', ',
+                    $cust_location->address1,
+                    $cust_location->city,
+                    $cust_location->state,
+                    $cust_location->zip
+      ) )
+    );
+    # this should not produce an address with sec_unit_type,
+    # so 'location' will be set to address2
+  }
+  if ( $location_hash ) {
+    # then store it
+    $hash{house_number}         = $location_hash->{number};
+    $hash{house_number_suffix}  = ''; # we don't support this, do we?
+    $hash{prefix_directional}   = $location_hash->{prefix};
+    $hash{street_name}          = $location_hash->{street};
+    $hash{street_suffix}        = $location_hash->{type};
+    $hash{post_directional}     = $location_hash->{suffix};
+    $hash{community_name}       = $location_hash->{city};
+    $hash{state}                = $location_hash->{state};
+    if ($location_hash->{sec_unit_type}) {
+      $hash{location} = $location_hash->{sec_unit_type} . ' ' .
+                        $location_hash->{sec_unit_num};
+    } else {
+      $hash{location} = $address2;
+    }
   } else {
-    $hash{location} = $cust_location->address2;
+    # then it still wouldn't parse; happens when the address has no house
+    # number (which is allowed in NENA 2 format). so just put all the 
+    # information we have into the record. (Parse::FixedLength will trim
+    # it to fit if necessary.)
+    $hash{street_name}    = uc($cust_location->address1);
+    $hash{location}       = uc($address2);
+    $hash{community_name} = uc($cust_location->city);
+    $hash{state}          = uc($cust_location->state);
   }
 
   # customer name and class

commit 74ed0dad3168f94cefc7cd24db9a19ea627c3a62
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Oct 22 11:56:38 2014 -0700

    ensure relocate export always runs exactly once, #14049

diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index cbd26a1..12e2c78 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -335,15 +335,34 @@ sub replace {
 
   #trigger a relocate export on location changes
   if ( $new->cust_pkg->locationnum != $old->cust_pkg->locationnum ) {
-    $error ||= $new->svc_x->export('relocate',
-                                   $new->cust_pkg->cust_location,
-                                   $old->cust_pkg->cust_location,
+    my $svc_x = $new->svc_x;
+    if ( $svc_x->locationnum ) {
+      if ( $svc_x->locationnum == $old->cust_pkg->locationnum ) {
+        # in this case, set the service location to be the same as the new
+        # package location
+        $svc_x->set('locationnum', $new->cust_pkg->locationnum);
+        # and replace it, which triggers a relocate export so we don't 
+        # need to
+        $error ||= $svc_x->replace;
+      } else {
+        # the service already has a different location from its package
+        # so don't change it
+      }
+    } else {
+      # the service doesn't have a locationnum (either isn't of a type 
+      # that has the locationnum field, or the locationnum is null and 
+      # defaults to cust_pkg->locationnum)
+      # so just trigger the export here
+      $error ||= $new->svc_x->export('relocate',
+                                     $new->cust_pkg->cust_location,
+                                     $old->cust_pkg->cust_location,
                                   );
-  }
+    } # if ($svc_x->locationnum)
+  } # if this is a location change
 
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
-    return $error if $error;
+    return $error if $error
   }
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;

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

Summary of changes:
 FS/FS/cust_svc.pm          |   29 +++++++++++++++----
 FS/FS/part_export/nena2.pm |   68 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 75 insertions(+), 22 deletions(-)




More information about the freeside-commits mailing list