summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorMitch Jackson <mitch@freeside.biz>2019-05-26 15:29:16 -0400
committerMitch Jackson <mitch@freeside.biz>2019-05-27 17:48:46 -0400
commit1b832fbb0757e4f694528a0685a6875ab2abc50a (patch)
treef345a76afb05a8c274910148c4da80e1aeeaf12d /FS/FS
parent3bfedb7199c3de10c0f2d9a0c7de675fed63c4d9 (diff)
RT# 83402 CLI tool to repair wa state tax tables
Diffstat (limited to 'FS/FS')
-rwxr-xr-xFS/FS/Cron/tax_rate_update.pm26
-rw-r--r--FS/FS/cust_main_county.pm34
2 files changed, 60 insertions, 0 deletions
diff --git a/FS/FS/Cron/tax_rate_update.pm b/FS/FS/Cron/tax_rate_update.pm
index bb9d4d1..4383bc5 100755
--- a/FS/FS/Cron/tax_rate_update.pm
+++ b/FS/FS/Cron/tax_rate_update.pm
@@ -294,6 +294,11 @@ 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();
+
$args->{temp_dir} ||= tempdir();
$args->{filename} ||= wa_sales_fetch_xlsx_file( $args );
@@ -635,6 +640,26 @@ sub wa_sales_fetch_xlsx_file {
}
+=head2 wa_sales_update_tax_table_sanity_check
+
+There should be no duplicate tax table entries in the tax table,
+with the same district value, within a tax class, where source=wa_sales.
+
+If there are, custome taxes may have been user-entered in the
+freeside UI, and incorrectly labelled as source=wa_sales. Or, the
+dupe record may have been created by issues with older wa_sales code.
+
+If these dupes exist, the sysadmin must solve the problem by hand
+with the freeeside-wa-tax-table-resolve script
+
+Returns 1 unless problem sales tax entries are detected
+
+=cut
+
+sub wa_sales_update_tax_table_sanity_check {
+ FS::cust_main_county->find_wa_tax_dupes ? 0 : 1;
+}
+
sub log {
state $log = FS::Log->new('tax_rate_update');
$log;
@@ -655,6 +680,7 @@ sub log_warn_and_warn {
sub log_error_and_die {
my $log_message = shift;
&log()->error( $log_message );
+ warn( "$log_message\n" );
die( "$log_message\n" );
}
diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm
index 2bd7342..9582334 100644
--- a/FS/FS/cust_main_county.pm
+++ b/FS/FS/cust_main_county.pm
@@ -562,6 +562,40 @@ sub taxline {
return $tax_item;
}
+=head1 find_wa_tax_dupes
+
+Return a list of cust_main_county Record objects that are detected
+as duplicate washington state sales tax rows (source=wa_state)
+within their respective tax classes
+
+=cut
+
+sub find_wa_tax_dupes {
+ my %cust_main_county;
+ my @dupes;
+
+ for my $row ( qsearch( cust_main_county => { source => 'wa_sales' } ) ) {
+ my $taxclass = $row->taxclass || 'none';
+ $cust_main_county{$taxclass} ||= {};
+
+ my $district = $row->district || 'none';
+ $cust_main_county{$taxclass}->{$district} ||= [];
+
+ push @{ $cust_main_county{$taxclass}->{$district} }, $row;
+ }
+
+ for my $taxclass ( keys %cust_main_county ) {
+ for my $district ( keys %{ $cust_main_county{$taxclass} } ) {
+ my $tax_rows = $cust_main_county{$taxclass}->{$district};
+ if ( scalar @$tax_rows > 1 ) {
+ push @dupes, @$tax_rows;
+ }
+ }
+ }
+
+ @dupes;
+}
+
=back
=head1 SUBROUTINES