From: Mitch Jackson Date: Mon, 27 May 2019 21:26:06 +0000 (-0400) Subject: RT# 83122 Do not auto-repair wa state sales tax rows X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=4ef042d6aea8b8922fc5cfb596023d04da4690be RT# 83122 Do not auto-repair wa state sales tax rows Dupe rows may actually be dupes, or they may be manually created taxes for other purposes! Pulled out auto-repair code, because it could be harming user's manually entered tax tables. When dupes are detected, wa sales taxes will not auto update, and instead generate error and log messages pointing user towardst the freeside-wa-tax-table-resolve CLI tool --- diff --git a/FS/FS/Cron/tax_rate_update.pm b/FS/FS/Cron/tax_rate_update.pm index 4383bc501..5111ef4d0 100755 --- a/FS/FS/Cron/tax_rate_update.pm +++ b/FS/FS/Cron/tax_rate_update.pm @@ -294,10 +294,13 @@ sub wa_sales_update_tax_table { ) ); - # The checks themselves will fully log details about the problem, - # so simple error message is sufficient here - log_error_and_die('abort tax table update, sanity checks failed') - unless wa_sales_update_tax_table_sanity_check(); + unless ( wa_sales_update_tax_table_sanity_check() ) { + log_error_and_die( + 'Duplicate district rows exist in the Washington state sales tax table. '. + 'These must be resolved before updating the tax tables. '. + 'See "freeside-wa-tax-table-resolve --check" to repair the tax tables. ' + ); + } $args->{temp_dir} ||= tempdir(); @@ -356,7 +359,7 @@ sub wa_sales_update_cust_main_county { cust_main_county => { source => 'wa_sales', district => { op => '!=', value => undef }, - tax_class => $taxclass, + taxclass => $taxclass, } ) ) { @@ -381,19 +384,30 @@ sub wa_sales_update_cust_main_county { $cust_main_county{$district} = $row; } - # Merge any dupes, place resulting non-dupe row in %cust_main_county - # Merge, even if one of the dupes has a $0 tax, or some other - # variation on tax row data. Data for this row will get corrected - # during the following tax import - for my $dupe_district_aref ( values %cust_main_county_dupe ) { - my $row_to_keep = shift @$dupe_district_aref; - while ( my $row_to_merge = shift @$dupe_district_aref ) { - $row_to_merge->_merge_into( - $row_to_keep, - { identical_record_check => 0 }, - ); - } - $cust_main_county{$row_to_keep->district} = $row_to_keep; + # # Merge any dupes, place resulting non-dupe row in %cust_main_county + # # Merge, even if one of the dupes has a $0 tax, or some other + # # variation on tax row data. Data for this row will get corrected + # # during the following tax import + # for my $dupe_district_aref ( values %cust_main_county_dupe ) { + # my $row_to_keep = shift @$dupe_district_aref; + # while ( my $row_to_merge = shift @$dupe_district_aref ) { + # $row_to_merge->_merge_into( + # $row_to_keep, + # { identical_record_check => 0 }, + # ); + # } + # $cust_main_county{$row_to_keep->district} = $row_to_keep; + # } + + # If there are duplicate rows, it may be unsafe to auto-resolve them + if ( %cust_main_county_dupe ) { + warn "Unable to continue!"; + log_error_and_die( sprintf( + 'Tax district duplicate rows detected(%s) - '. + 'WA Sales tax tables cannot be updated without resolving duplicates - '. + 'Please use tool freeside-wa-tax-table-resolve for tax table repair', + join( ',', keys %cust_main_county_dupe ) + )); } for my $district ( @{ $args->{tax_districts} } ) {