proceed with a CCH update even if some GEOCODE/tax_rate_location deletions can't...
[freeside.git] / FS / FS / tax_rate_location.pm
index 218ed97..aeb14d3 100644 (file)
@@ -151,6 +151,37 @@ sub check {
 
 =back
 
+=head1 CLASS METHODS
+
+=item location_sql KEY => VALUE, ...
+
+Returns an SQL fragment identifying matching tax_rate_location /
+cust_bill_pkg_tax_rate_location records.
+
+Parameters are county, state, city and locationtaxid
+
+=cut
+
+sub location_sql {
+  my($class, %param) = @_;
+
+  my %pn = (
+   'city'          => 'tax_rate_location.city',
+   'county'        => 'tax_rate_location.county',
+   'state'         => 'tax_rate_location.state',
+   'locationtaxid' => 'cust_bill_pkg_tax_rate_location.locationtaxid',
+  );
+
+  my %ph = map { $pn{$_} => dbh->quote($param{$_}) } keys %pn;
+
+  join( ' AND ',
+    map { "( $_ = $ph{$_} OR $ph{$_} = '' AND $_ IS NULL)" } keys %ph
+  );
+
+}
+
+=back
+
 =head1 SUBROUTINES
 
 =over 4
@@ -203,13 +234,14 @@ sub batch_import {
 
         $hash->{disabled} = '';
         my $tax_rate_location = qsearchs('tax_rate_location', $hash);
-        return "Can't find tax_rate_location to delete: ".
-               join(" ", map { "$_ => ". $hash->{$_} } @fields)
-          unless $tax_rate_location;
-
-        $tax_rate_location->disabled('Y');
-        my $error = $tax_rate_location->replace;
-        return $error if $error;
+        if ( $tax_rate_location ) {
+          $tax_rate_location->disabled('Y');
+          my $error = $tax_rate_location->replace;
+          return $error if $error;
+        } else {
+          warn "WARNING: Can't find tax_rate_location to delete, continuing update anyway: ".
+                 join(" ", map { "$_ => ". $hash->{$_} } @fields);
+        }
 
         delete($hash->{$_}) foreach (keys %$hash);
       }
@@ -270,7 +302,7 @@ sub batch_import {
     }
     if ( scalar( @columns ) ) {
       $dbh->rollback if $oldAutoCommit;
-      return "Unexpected trailing columns in line (wrong format?): $line";
+      return "Unexpected trailing columns in line (wrong format?) importing tax-rate_location: $line";
     }
 
     my $error = &{$hook}(\%tax_rate_location);