From: Ivan Kohler Date: Wed, 8 May 2013 09:55:51 +0000 (-0700) Subject: fix CCH update adding a TAXCAT, RT#21687 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=9732b34df2fad5f09751766378c05eacd671e4fb fix CCH update adding a TAXCAT, RT#21687 --- diff --git a/FS/FS/tax_class.pm b/FS/FS/tax_class.pm index eeb8993ee..15f9a42a6 100644 --- a/FS/FS/tax_class.pm +++ b/FS/FS/tax_class.pm @@ -253,21 +253,28 @@ sub batch_import { } } - my $tax_class = - new FS::tax_class( { 'data_vendor' => 'cch', - 'taxclass' => $type->[0].':'.$cat->[0], - 'description' => $type->[1].':'.$cat->[1], - } ); - my $error = $tax_class->insert; - return "can't insert tax_class for old TAXTYPE $type and new TAXCAT $cat: $error" if $error; + my %hash = ( 'data_vendor' => 'cch', + 'taxclass' => $type->[0].':'.$cat->[0], + 'description' => $type->[1].':'.$cat->[1], + ); + unless ( qsearchs('tax_class', \%hash) ) { + my $tax_class = new FS::tax_class \%hash; + my $error = $tax_class->insert; + + return "can't insert tax_class for ". + " old TAXTYPE ". $type->[0].':'.$type->[1]. + " and new TAXCAT ". $cat->[0].':'. $cat->[1]. + " : $error" + if $error; + } + $imported++; + } } - my %cats = map { $_=>1 } ( @old_cats, @{$data->{'taxcat'}} ); - foreach my $type (@{$data->{'taxtype'}}) { - foreach my $cat (keys %cats) { + foreach my $cat (@old_cats, @{$data->{'taxcat'}}) { if ( $job ) { # progress bar if ( time - $min_sec > $last ) {