From 66720bf1f5bae4b1d4022eabff456c247447fbc1 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 8 May 2013 13:33:24 -0700 Subject: [PATCH] fix cch update removal of PLUS4/ZIP and TXMATRIX, RT#21687 --- FS/FS/cust_tax_location.pm | 10 ++++++---- FS/FS/part_pkg_taxrate.pm | 13 +++++++------ FS/FS/tax_rate.pm | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/FS/FS/cust_tax_location.pm b/FS/FS/cust_tax_location.pm index 1a9bf5a41..aec941045 100644 --- a/FS/FS/cust_tax_location.pm +++ b/FS/FS/cust_tax_location.pm @@ -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); } diff --git a/FS/FS/part_pkg_taxrate.pm b/FS/FS/part_pkg_taxrate.pm index c83f700d9..a73272040 100644 --- a/FS/FS/part_pkg_taxrate.pm +++ b/FS/FS/part_pkg_taxrate.pm @@ -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); } diff --git a/FS/FS/tax_rate.pm b/FS/FS/tax_rate.pm index 721d5f583..265383398 100644 --- a/FS/FS/tax_rate.pm +++ b/FS/FS/tax_rate.pm @@ -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; } } -- 2.11.0