fix cch update removal of PLUS4/ZIP and TXMATRIX, RT#21687
authorIvan Kohler <ivan@freeside.biz>
Wed, 8 May 2013 20:33:24 +0000 (13:33 -0700)
committerIvan Kohler <ivan@freeside.biz>
Wed, 8 May 2013 20:33:24 +0000 (13:33 -0700)
FS/FS/cust_tax_location.pm
FS/FS/part_pkg_taxrate.pm
FS/FS/tax_rate.pm

index 1a9bf5a..aec9410 100644 (file)
@@ -234,13 +234,15 @@ sub batch_import {
       if (exists($hash->{actionflag}) && $hash->{actionflag} eq 'D') {
         delete($hash->{actionflag});
 
-        my $cust_tax_location = qsearchs('cust_tax_location', $hash);
+        my @cust_tax_location = qsearch('cust_tax_location', $hash);
         return "Can't find cust_tax_location to delete: ".
                join(" ", map { "$_ => ". $hash->{$_} } @fields)
-          unless $cust_tax_location;
+          unless scalar(@cust_tax_location) || $param->{'delete_only'} ;
 
-        my $error = $cust_tax_location->delete;
-        return $error if $error;
+        foreach my $cust_tax_location (@cust_tax_location) {
+          my $error = $cust_tax_location->delete;
+          return $error if $error;
+        }
 
         delete($hash->{$_}) foreach (keys %$hash);
       }
index c83f700..a732720 100644 (file)
@@ -5,8 +5,7 @@ use vars qw( @ISA );
 use Date::Parse;
 use DateTime;
 use DateTime::Format::Strptime;
-use FS::UID qw(dbh);
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 use FS::part_pkg_taxproduct;
 use FS::Misc qw(csv_from_fixed);
 
@@ -310,8 +309,8 @@ sub batch_import {
           }
         }
 
-        my $part_pkg_taxrate = qsearchs('part_pkg_taxrate', $hash);
-        unless ( $part_pkg_taxrate ) {
+        my @part_pkg_taxrate = qsearch('part_pkg_taxrate', $hash);
+        unless ( scalar(@part_pkg_taxrate) || $param->{'delete_only'} ) {
           if ( $hash->{taxproductnum} ) {
             my $taxproduct =
               qsearchs( 'part_pkg_taxproduct',
@@ -324,8 +323,10 @@ sub batch_import {
                  join(" ", map { "$_ => *". $hash->{$_}. '*' } keys(%$hash) );
         }
 
-        my $error = $part_pkg_taxrate->delete;
-        return $error if $error;
+        foreach my $part_pkg_taxrate (@part_pkg_taxrate) {
+          my $error = $part_pkg_taxrate->delete;
+          return $error if $error;
+        }
 
         delete($hash->{$_}) foreach (keys %$hash);
       }
index 721d5f5..2653833 100644 (file)
@@ -967,7 +967,7 @@ sub _perform_batch_import {
       my $file = lc($name). 'file';
 
       unless ($files{$file}) {
-        $error = "No $name supplied";
+        #$error = "No $name supplied";
         next;
       }
       next if $name eq 'DETAIL' && $format =~ /update/;
@@ -1002,10 +1002,17 @@ sub _perform_batch_import {
       'DETAIL', "$dir/".$files{detailfile}, \&FS::tax_rate::batch_import, $format
       if $format =~ /update/;
 
+    my %addl_param = ();
+    if ( $param->{'delete_only'} ) {
+      $addl_param{'delete_only'} = $param->{'delete_only'};
+      @insert_list = () 
+    }
+
     $error ||= _perform_cch_tax_import( $job,
                                         [ @predelete_list ],
                                         [ @insert_list ],
                                         [ @delete_list ],
+                                        \%addl_param,
     );
     
     
@@ -1030,7 +1037,8 @@ sub _perform_batch_import {
 
 
 sub _perform_cch_tax_import {
-  my ( $job, $predelete_list, $insert_list, $delete_list ) = @_;
+  my ( $job, $predelete_list, $insert_list, $delete_list, $addl_param ) = @_;
+  $addl_param ||= {};
 
   my $error = '';
   foreach my $list ($predelete_list, $insert_list, $delete_list) {
@@ -1039,7 +1047,11 @@ sub _perform_cch_tax_import {
       my $fmt = "$format-update";
       $fmt = $format. ( lc($name) eq 'zip' ? '-zip' : '' );
       open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
-      $error ||= &{$method}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
+      my $param = { 'filehandle' => $fh,
+                    'format'     => $fmt,
+                    %$addl_param,
+                  };
+      $error ||= &{$method}($param, $job);
       close $fh;
     }
   }