X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_location.pm;h=21bf92feba0e75dcb246dc7faf57ca7b21483910;hp=fee77a8b106b3eb730f9d6fc88e026cedb089e9a;hb=5372897f367498972c96f5494e142e6e11b29eb8;hpb=d8dcec0a073b96794328195d4327e28b56996705 diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index fee77a8b1..21bf92feb 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -265,8 +265,15 @@ sub insert { return $error; } - #false laziness with cust_main, will go away eventually - if ( !$import and $conf->config('tax_district_method') ) { + # If using tax_district_method, for rows in state of Washington, + # without a tax district already specified, queue a job to find + # the tax district + if ( + !$import + && !$self->district + && lc $self->state eq 'wa' + && $conf->config('tax_district_method') + ) { my $queue = new FS::queue { 'job' => 'FS::geocode_Mixin::process_district_update' @@ -436,6 +443,26 @@ sub check { && $conf->exists('prospect_main-alt_address_format') && ! $self->location_kind; + # Do not allow bad tax district values in cust_location when + # using Washington State district sales tax calculation - would result + # in incorrect or missing sales tax on invoices. + my $tax_district_method = FS::Conf->new->config('tax_district_method'); + if ( + $tax_district_method + && $tax_district_method eq 'wa_sales' + && $self->district + ) { + my $cust_main_county = qsearchs( + cust_main_county => { district => $self->district } + ); + unless ( ref $cust_main_county ) { + return sprintf ( + 'WA State tax district %s does not exist in tax table', + $self->district + ); + } + } + unless ( $import or qsearch('cust_main_county', { 'country' => $self->country, 'state' => '', @@ -990,7 +1017,11 @@ sub _upgrade_data { die "$error (fixing whitespace in $field, locationnum ".$location->locationnum.')' if $error; - if ( $use_districts ) { + if ( + $use_districts + && !$location->district + && lc $location->state eq 'wa' + ) { my $queue = new FS::queue { 'job' => 'FS::geocode_Mixin::process_district_update' };