[freeside-commits] branch FREESIDE_3_BRANCH updated. 6b2ca62ba039622bf60715bacb9c6aabee0510bc

Ivan ivan at 420.am
Sun Apr 27 17:43:57 PDT 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  6b2ca62ba039622bf60715bacb9c6aabee0510bc (commit)
      from  45e80dcb65ede22713ea6795a89729429392d504 (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 6b2ca62ba039622bf60715bacb9c6aabee0510bc
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Apr 27 17:43:56 2014 -0700

    allow cust_http export to be triggered for location changes, RT#22830

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 7336a9e..8eeec0b 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5222,6 +5222,33 @@ and customer address. Include units.',
     },
   },
 
+  #false laziness w/above options_sub and option_sub
+  {
+    'key'         => 'cust_location-exports',
+    'section'     => '',
+    'description' => 'Export(s) to call on cust_location insert, modification and deletion.',
+    'type'        => 'select-sub',
+    'multiple'    => 1,
+    'options_sub' => sub {
+      require FS::Record;
+      require FS::part_export;
+      my @part_export =
+        map { qsearch( 'part_export', {exporttype => $_ } ) }
+          keys %{FS::part_export::export_info('cust_location')};
+      map { $_->exportnum => $_->exporttype.' to '.$_->machine } @part_export;
+    },
+    'option_sub'  => sub {
+      require FS::Record;
+      require FS::part_export;
+      my $part_export = FS::Record::qsearchs(
+        'part_export', { 'exportnum' => shift }
+      );
+      $part_export
+        ? $part_export->exporttype.' to '.$part_export->machine
+        : '';
+    },
+  },
+
   {
     'key'         => 'cust_tag-location',
     'section'     => 'UI',
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm
index 51fcba3..8412a39 100644
--- a/FS/FS/cust_location.pm
+++ b/FS/FS/cust_location.pm
@@ -12,6 +12,7 @@ use FS::Conf;
 use FS::prospect_main;
 use FS::cust_main;
 use FS::cust_main_county;
+use FS::part_export;
 use FS::GeocodeCache;
 
 $import = 0;
@@ -205,19 +206,49 @@ sub insert {
     $self->set('censusyear' => $conf->config('census_year') || 2012);
   }
 
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
   my $error = $self->SUPER::insert(@_);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
 
   #false laziness with cust_main, will go away eventually
-  if ( !$import and !$error and $conf->config('tax_district_method') ) {
+  if ( !$import and $conf->config('tax_district_method') ) {
 
     my $queue = new FS::queue {
       'job' => 'FS::geocode_Mixin::process_district_update'
     };
     $error = $queue->insert( ref($self), $self->locationnum );
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
 
   }
 
-  $error || '';
+  # cust_location exports
+  #my $export_args = $options{'export_args'} || [];
+
+  my @part_export =
+    map qsearch( 'part_export', {exportnum=>$_} ),
+      $conf->config('cust_location-exports'); #, $agentnum
+
+  foreach my $part_export ( @part_export ) {
+    my $error = $part_export->export_insert($self); #, @$export_args);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "exporting to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 =item delete
@@ -242,7 +273,35 @@ sub replace {
     }
   }
 
-  $self->SUPER::replace($old);
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error = $self->SUPER::replace($old);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  # cust_location exports
+  #my $export_args = $options{'export_args'} || [];
+
+  my @part_export =
+    map qsearch( 'part_export', {exportnum=>$_} ),
+      $conf->config('cust_location-exports'); #, $agentnum
+
+  foreach my $part_export ( @part_export ) {
+    my $error = $part_export->export_replace($self, $old); #, @$export_args);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "exporting to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 
@@ -598,6 +657,16 @@ sub county_state_country {
   $label;
 }
 
+=item cust_main
+
+=cut
+
+sub cust_main {
+  my $self = shift;
+  return '' unless $self->custnum;
+  qsearchs('cust_main', { 'custnum' => $self->custnum } );
+}
+
 =back
 
 =head1 CLASS METHODS
diff --git a/FS/FS/part_export/cust_http.pm b/FS/FS/part_export/cust_http.pm
index e834f93..5ccb403 100644
--- a/FS/FS/part_export/cust_http.pm
+++ b/FS/FS/part_export/cust_http.pm
@@ -19,10 +19,10 @@ tie %options, 'Tie::IxHash',
     default => join("\n",
       "action  'insert'",
       "custnum \$cust_main->custnum",
-      "first   \$cust_main->first",
-      "last    \$cust_main->get('last')",
-      ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax  last ) ),
-      "email   \$cust_main->invoicing_list_emailonly_scalar",
+#      "first   \$cust_main->first",
+#      "last    \$cust_main->get('last')",
+#      ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax ) ),
+#      "email   \$cust_main->invoicing_list_emailonly_scalar",
     ),
   },
   'delete_data' => {
@@ -39,10 +39,10 @@ tie %options, 'Tie::IxHash',
     default => join("\n",
       "action  'replace'",
       "custnum \$new_cust_main->custnum",
-      "first   \$new_cust_main->first",
-      "last    \$new_cust_main->get('last')",
-      ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax  last ) ),
-      "email   \$new_cust_main->invoicing_list_emailonly_scalar",
+#      "first   \$new_cust_main->first",
+#      "last    \$new_cust_main->get('last')",
+#      ( map "$_ \$cust_main->$_", qw( company address1 address2 city county state zip country daytime night fax ) ),
+#      "email   \$new_cust_main->invoicing_list_emailonly_scalar",
     ),
   },
   'success_regexp' => {
@@ -52,7 +52,7 @@ tie %options, 'Tie::IxHash',
 ;
 
 %info = (
-  'svc'     => 'cust_main',
+  'svc'     => [qw( cust_main cust_location )],
   'desc'    => 'Send an HTTP or HTTPS GET or POST request, for customers.',
   'options' => \%options,
   'no_machine' => 1,
diff --git a/FS/FS/part_export/http.pm b/FS/FS/part_export/http.pm
index 0d62409..aeeb59b 100644
--- a/FS/FS/part_export/http.pm
+++ b/FS/FS/part_export/http.pm
@@ -91,9 +91,7 @@ sub _export_command {
 
   return unless $self->option("${action}_data");
 
-  my $cust_main = $svc_x->table eq 'cust_main'
-                    ? $svc_x
-                    : $svc_x->cust_svc->cust_pkg->cust_main;
+  my $cust_main = $svc_x->cust_main or return;
 
   $self->http_queue( $svc_x->svcnum,
     $self->option('method'),
@@ -115,9 +113,7 @@ sub _export_replace {
 
   return unless $self->option('replace_data');
 
-  my $new_cust_main = $new->table eq 'cust_main'
-                        ? $new
-                        : $new->cust_svc->cust_pkg->cust_main;
+  my $new_cust_main = $new->cust_main or return;
   my $cust_main = $new_cust_main; #so folks can use $new_cust_main or $cust_main
 
   $self->http_queue( $new->svcnum,

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

Summary of changes:
 FS/FS/Conf.pm                  |   27 ++++++++++++++
 FS/FS/cust_location.pm         |   75 ++++++++++++++++++++++++++++++++++++++--
 FS/FS/part_export/cust_http.pm |   18 +++++-----
 FS/FS/part_export/http.pm      |    8 +---
 4 files changed, 110 insertions(+), 18 deletions(-)




More information about the freeside-commits mailing list