my $taxname = $conf->config('tax_district_taxname') || '';
+ FS::cust_main_county->lock_table;
if ($method eq 'wa_sales') {
# download the update file
my $now = DateTime->now;
die $@ if $@;
die "$class has no location data" if !$class->can('location_hash');
+ my $error;
my $conf = FS::Conf->new;
my $method = $conf->config('tax_district_method')
or return; #nothing to do if null
my $tax_info = get_district({ $self->location_hash }, $method);
return unless $tax_info;
- $self->set('district', $tax_info->{'district'} );
- my $error = $self->replace;
- die $error if $error;
+ if ($self->district ne $tax_info->{'district'}) {
+ $self->set('district', $tax_info->{'district'} );
+ $error = $self->replace;
+ die $error if $error;
+ }
my %hash = map { $_ => uc( $tax_info->{$_} ) }
qw( district city county state country );
my $taxname = $conf->config('tax_district_taxname');
# there must be exactly one cust_main_county for each district+taxclass.
# do NOT exclude taxes that are zero.
+
+ # mutex here so that concurrent queue jobs can't make duplicates.
+ FS::cust_main_county->lock_table;
foreach my $taxclass (@classes) {
my @existing = qsearch('cust_main_county', {
%hash,
if ( $dbh->{Driver}->{Name} =~ /^mysql/i && ! $opt_s ) {
- foreach my $table (qw( svc_acct svc_phone )) {
+ foreach my $table (qw( svc_acct svc_phone cust_main_county )) {
my $sth = $dbh->prepare(
"SELECT COUNT(*) FROM duplicate_lock WHERE lockname = '$table'"