[freeside-commits] freeside/FS/FS tax_rate.pm, 1.28, 1.29 tax_rate_location.pm, 1.2, 1.3

Jeff Finucane,420,, jeff at wavetail.420.am
Mon Jul 13 09:02:34 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv15902/FS/FS

Modified Files:
	tax_rate.pm tax_rate_location.pm 
Log Message:
correct ordering and other bugs in tax updates

Index: tax_rate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_rate.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- tax_rate.pm	19 Jun 2009 21:49:03 -0000	1.28
+++ tax_rate.pm	13 Jul 2009 16:02:31 -0000	1.29
@@ -917,6 +917,7 @@
     my $error = '';
     my @insert_list = ();
     my @delete_list = ();
+    my @predelete_list = ();
 
     my @list = ( 'GEOCODE',  'geofile',   \&FS::tax_rate_location::batch_import,
                  'CODE',     'codefile',  \&FS::tax_class::batch_import,
@@ -972,9 +973,26 @@
       close $dfh;
 
       push @insert_list, $name, $ifh->filename, $import_sub;
-      unshift @delete_list, $name, $dfh->filename, $import_sub;
+      if ( $name eq 'GEOCODE' ) { #handle this whole ordering issue better
+        unshift @predelete_list, $name, $dfh->filename, $import_sub;
+      } else {
+        unshift @delete_list, $name, $dfh->filename, $import_sub;
+      }
 
     }
+
+    while( scalar(@predelete_list) ) {
+      my ($name, $file, $import_sub) =
+        (shift @predelete_list, shift @predelete_list, shift @predelete_list);
+
+      my $fmt = $format. ( $name eq 'ZIP' ? '-zip' : '' );
+      open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
+      $error ||=
+        &{$import_sub}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
+      close $fh;
+      unlink $file or warn "Can't delete $file: $!";
+    }
+    
     while( scalar(@insert_list) ) {
       my ($name, $file, $import_sub) =
         (shift @insert_list, shift @insert_list, shift @insert_list);
@@ -1316,7 +1334,7 @@
     if (-d $dir) {
 
       if (-d "$dir.4") {
-        opendir(my $dirh, $dir) or die "failed to open $dir.4: $!\n";
+        opendir(my $dirh, "$dir.4") or die "failed to open $dir.4: $!\n";
         foreach my $file (readdir($dirh)) {
           unlink "$dir.4/$file" if (-f "$dir.4/$file");
         }
@@ -1426,6 +1444,7 @@
 
     my @insert_list = ();
     my @delete_list = ();
+    my @predelete_list = ();
 
     my @list = (
                  'geocode',  \&FS::tax_rate_location::batch_import, 
@@ -1491,13 +1510,31 @@
       %oldlines = ();
 
       push @insert_list, $name, $ifh->filename, $method;
-      unshift @delete_list, $name, $dfh->filename, $method
-        unless $name eq 'detail';
+      if ( $name eq 'geocode' ) {
+        unshift @predelete_list, $name, $dfh->filename, $method
+          unless $name eq 'detail';
+      } else {
+        unshift @delete_list, $name, $dfh->filename, $method
+          unless $name eq 'detail';
+      }
 
       close $dfh;
       close $ifh;
     }
 
+    while( scalar(@predelete_list) ) {
+      my ($name, $file, $method) =
+        (shift @predelete_list, shift @predelete_list, shift @predelete_list);
+
+      my $fmt = "$format-update";
+      $fmt = $fmt. ( $name eq 'zip' ? '-zip' : '' );
+      open my $fh, "< $file" or $error ||= "Can't open $name file $file: $!";
+      $error ||=
+        &{$method}({ 'filehandle' => $fh, 'format' => $fmt }, $job);
+      close $fh;
+      #unlink $file or warn "Can't delete $file: $!";
+    }
+
     while( scalar(@insert_list) ) {
       my ($name, $file, $method) =
         (shift @insert_list, shift @insert_list, shift @insert_list);

Index: tax_rate_location.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_rate_location.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- tax_rate_location.pm	18 May 2009 19:23:27 -0000	1.2
+++ tax_rate_location.pm	13 Jul 2009 16:02:32 -0000	1.3
@@ -125,11 +125,18 @@
   ;
   return $error if $error;
 
-  my $t = qsearchs( 'tax_rate_location',
-                    { map { $_ => $self->$_ } qw( data_vendor geocode ) },
-                  );
+  my $t;
+  $t = qsearchs( 'tax_rate_location',
+                 { disabled => '',
+                   ( map { $_ => $self->$_ } qw( data_vendor geocode ) ),
+                 },
+               )
+    unless $self->disabled;
 
-  return "geocode already in use for this vendor"
+  $t = $self->by_key( $self->taxratelocationnum )
+    if ( !$t && $self->taxratelocationnum );
+
+  return "geocode ". $self->geocode. " already in use for this vendor"
     if ( $t && $t->taxratelocationnum != $self->taxratelocationnum );
 
   return "may only be disabled"
@@ -194,7 +201,7 @@
       if (exists($hash->{'actionflag'}) && $hash->{'actionflag'} eq 'D') {
         delete($hash->{actionflag});
 
-        $hash->{deleted} = '';
+        $hash->{disabled} = '';
         my $tax_rate_location = qsearchs('tax_rate_location', $hash);
         return "Can't find tax_rate_location to delete: ".
                join(" ", map { "$_ => ". $hash->{$_} } @fields)
@@ -279,7 +286,7 @@
 
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
-        return "can't insert tax_rate for $line: $error";
+        return "can't insert tax_rate_location for $line: $error";
       }
 
     }



More information about the freeside-commits mailing list