[freeside-commits] branch master updated. 94c1d035193d1eabb1820e62bce96438f11f870a

Ivan ivan at 420.am
Tue Aug 7 23:08:55 PDT 2012


The branch, master has been updated
       via  94c1d035193d1eabb1820e62bce96438f11f870a (commit)
      from  21254f0e0062b92c19530c49c6eacc9ce3e93827 (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 94c1d035193d1eabb1820e62bce96438f11f870a
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Aug 7 23:08:53 2012 -0700

    ignore extra columns in CCH diff (bad data from last update?), RT#18817

diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm
index 3fdaa1e..a5a623d 100644
--- a/FS/FS/tax_rate.pm
+++ b/FS/FS/tax_rate.pm
@@ -10,6 +10,7 @@ use DateTime::Format::Strptime;
 use Storable qw( thaw nfreeze );
 use IO::File;
 use File::Temp;
+use Text::CSV_XS;
 use LWP::UserAgent;
 use HTTP::Request;
 use HTTP::Response;
@@ -637,6 +638,7 @@ sub batch_import {
   $count *=2;
 
   if ( $format eq 'cch' || $format eq 'cch-update' ) {
+    #false laziness w/below (sub _perform_cch_diff)
     @fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
                   excessrate effective_date taxauth taxtype taxcat taxname
                   usetax useexcessrate fee unittype feemax maxtype passflag
@@ -715,9 +717,6 @@ sub batch_import {
     die "unknown format $format";
   }
 
-  eval "use Text::CSV_XS;";
-  die $@ if $@;
-
   my $csv = new Text::CSV_XS;
 
   my $imported = 0;
@@ -759,12 +758,10 @@ sub batch_import {
       $tax_rate{$field} = shift @columns; 
     }
 
-    #ignoring extra columns (bad data from last update?) and seeing if that
-    # allows the upgrade to proceed
-    #if ( scalar( @columns ) ) {
-    #  $dbh->rollback if $oldAutoCommit;
-    #  return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
-    #}
+    if ( scalar( @columns ) ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "Unexpected trailing columns in line (wrong format?) importing tax_rate: $line";
+    }
 
     my $error = &{$hook}(\%tax_rate);
     if ( $error ) {
@@ -1118,8 +1115,26 @@ sub _perform_cch_diff {
   }
   close $newcsvfh;
 
-  for (keys %oldlines) {
-    print $dfh $_, ',"D"', "\n" if $oldlines{$_};
+  #false laziness w/above (sub batch_import)
+  my @fields = qw( geocode inoutcity inoutlocal tax location taxbase taxmax
+                   excessrate effective_date taxauth taxtype taxcat taxname
+                   usetax useexcessrate fee unittype feemax maxtype passflag
+                   passtype basetype );
+  my $numfields = scalar(@fields);
+
+  my $csv = new Text::CSV_XS { 'always_quote' => 1 };
+
+  for my $line (grep $oldlines{$_}, keys %oldlines) {
+
+    $csv->parse($line) or do {
+      #$dbh->rollback if $oldAutoCommit;
+      die "can't parse: ". $csv->error_input();
+    };
+    my @columns = $csv->fields();
+    
+    $csv->combine( splice(@columns, 0, $numfields) );
+
+    print $dfh $csv->string, ',"D"', "\n";
   }
 
   close $dfh;
@@ -1173,9 +1188,6 @@ sub _cch_fetch_and_unzip {
 sub _cch_extract_csv_from_dbf {
   my ( $job, $dir, $name ) = @_;
 
-  eval "use Text::CSV_XS;";
-  die $@ if $@;
-
   eval "use XBase;";
   die $@ if $@;
 

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

Summary of changes:
 FS/FS/tax_rate.pm |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list