summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2016-11-16 17:10:12 -0800
committerIvan Kohler <ivan@freeside.biz>2016-11-16 17:10:12 -0800
commita5a541f3b1db3192f7d4a7dd5ad1fbf5800ef586 (patch)
treeda68fc589524586871787b696ca00a3763992de8 /FS
parent4090933e1de8cae6ed89794a5bbacf3b3ed434d5 (diff)
parent2dff574c971b18e3b3c74653e7e1376b7b57c3bb (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'FS')
-rwxr-xr-xFS/FS/Cron/tax_rate_update.pm1
-rw-r--r--FS/FS/Misc/Geo.pm4
-rw-r--r--FS/FS/TaxEngine/billsoft.pm1
-rw-r--r--FS/FS/cust_main_county.pm45
-rw-r--r--FS/FS/geocode_Mixin.pm12
-rwxr-xr-xFS/bin/freeside-upgrade2
6 files changed, 37 insertions, 28 deletions
diff --git a/FS/FS/Cron/tax_rate_update.pm b/FS/FS/Cron/tax_rate_update.pm
index 2c021b80e..b6ac63c2e 100755
--- a/FS/FS/Cron/tax_rate_update.pm
+++ b/FS/FS/Cron/tax_rate_update.pm
@@ -40,6 +40,7 @@ sub tax_rate_update {
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;
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm
index 92490bb3b..6b3d6ca71 100644
--- a/FS/FS/Misc/Geo.pm
+++ b/FS/FS/Misc/Geo.pm
@@ -210,13 +210,13 @@ sub wa_sales {
if ( lc($text) eq 'location code' ) {
$p->get_tag('td'); # skip to the next column
undef $u;
- $u = $p->get_token until $u->[0] eq 'T'; # and then skip non-text
+ $u = $p->get_token until ($u->[0] || '') eq 'T'; # and then skip non-text
$return->{'district'} = $u->[1];
}
elsif ( lc($text) eq 'total tax rate' ) {
$p->get_tag('td');
undef $u;
- $u = $p->get_token until $u->[0] eq 'T';
+ $u = $p->get_token until ($u->[0] || '') eq 'T';
$return->{'tax'} = $u->[1];
}
} # get_token
diff --git a/FS/FS/TaxEngine/billsoft.pm b/FS/FS/TaxEngine/billsoft.pm
index d262aa4d3..6bda8db37 100644
--- a/FS/FS/TaxEngine/billsoft.pm
+++ b/FS/FS/TaxEngine/billsoft.pm
@@ -105,6 +105,7 @@ sub create_batch {
my %sales;
foreach my $cust_bill_pkg ( $cust_bill->cust_bill_pkg ) {
+$DB::single = 1;
my $cust_pkg = $cust_pkg{$cust_bill_pkg->pkgnum}
||= $cust_bill_pkg->cust_pkg;
my $pkgpart = $cust_bill_pkg->pkgpart_override || $cust_pkg->pkgpart;
diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm
index 924f9bf19..5325fa562 100644
--- a/FS/FS/cust_main_county.pm
+++ b/FS/FS/cust_main_county.pm
@@ -717,7 +717,7 @@ sub _upgrade_data {
my $class = shift;
# assume taxes in Washington with district numbers, and null name, or
# named 'sales tax', are looked up via the wa_sales method. mark them.
- my $journal = 'cust_main_county__source_wa_sales';
+ my $journal = 'cust_main_county__source_wa_sales_201611';
if (!FS::upgrade_journal->is_done($journal)) {
my @taxes = qsearch({
'table' => 'cust_main_county',
@@ -737,26 +737,6 @@ sub _upgrade_data {
}
my @key_fields = (qw(city county state country district taxname taxclass));
- # remove duplicates (except disabled records)
- my @duplicate_sets = qsearch({
- table => 'cust_main_county',
- select => FS::Record::group_concat_sql('taxnum', ',') . ' AS taxnums, ' .
- join(',', @key_fields),
- extra_sql => ' WHERE tax > 0
- GROUP BY city, county, state, country, district, taxname, taxclass
- HAVING COUNT(*) > 1'
- });
- warn "Found ".scalar(@duplicate_sets)." set(s) of duplicate tax definitions\n"
- if @duplicate_sets;
- foreach my $set (@duplicate_sets) {
- my @taxnums = split(',', $set->get('taxnums'));
- my $first = FS::cust_main_county->by_key(shift @taxnums);
- foreach my $taxnum (@taxnums) {
- my $record = FS::cust_main_county->by_key($taxnum);
- $record->_merge_into($first);
- }
- }
-
# trim whitespace and convert to uppercase in the 'city' field.
foreach my $record (qsearch({
table => 'cust_main_county',
@@ -782,7 +762,7 @@ sub _upgrade_data {
my $district_taxname = $conf->config('tax_district_taxname');
$journal = 'cust_main_county__district_taxclass';
if (!FS::upgrade_journal->is_done($journal)
- and $conf->config('enable_taxclasses')) {
+ and $conf->exists('enable_taxclasses')) {
eval "use FS::part_pkg_taxclass";
my @taxes = qsearch({
'table' => 'cust_main_county',
@@ -856,6 +836,27 @@ sub _upgrade_data {
}
}
}
+
+ # remove duplicates (except disabled records)
+ my @duplicate_sets = qsearch({
+ table => 'cust_main_county',
+ select => FS::Record::group_concat_sql('taxnum', ',') . ' AS taxnums, ' .
+ join(',', @key_fields),
+ extra_sql => ' WHERE tax > 0
+ GROUP BY city, county, state, country, district, taxname, taxclass
+ HAVING COUNT(*) > 1'
+ });
+ warn "Found ".scalar(@duplicate_sets)." set(s) of duplicate tax definitions\n"
+ if @duplicate_sets;
+ foreach my $set (@duplicate_sets) {
+ my @taxnums = split(',', $set->get('taxnums'));
+ my $first = FS::cust_main_county->by_key(shift @taxnums);
+ foreach my $taxnum (@taxnums) {
+ my $record = FS::cust_main_county->by_key($taxnum);
+ $record->_merge_into($first);
+ }
+ }
+
'';
}
diff --git a/FS/FS/geocode_Mixin.pm b/FS/FS/geocode_Mixin.pm
index 46f8128aa..ef16e741d 100644
--- a/FS/FS/geocode_Mixin.pm
+++ b/FS/FS/geocode_Mixin.pm
@@ -260,6 +260,7 @@ sub process_district_update {
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
@@ -269,9 +270,11 @@ sub process_district_update {
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 );
@@ -281,6 +284,9 @@ sub process_district_update {
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,
diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade
index 77087c373..ffd574eea 100755
--- a/FS/bin/freeside-upgrade
+++ b/FS/bin/freeside-upgrade
@@ -298,7 +298,7 @@ print "\n" if $DRY_RUN;
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'"