[freeside-commits] branch FREESIDE_4_BRANCH updated. f54d295490980875e4762ee008b9de7c6471ec77
Mark Wells
mark at 420.am
Tue Nov 1 01:48:20 PDT 2016
The branch, FREESIDE_4_BRANCH has been updated
via f54d295490980875e4762ee008b9de7c6471ec77 (commit)
via 30b057bd3af55b3438139486bd87d651540e674d (commit)
via 4f8a5196a48ff735bbff2d17c96cd48e7ba54f4b (commit)
from f547547db67966ac04a3ccf97e6a6cb972beca2e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f54d295490980875e4762ee008b9de7c6471ec77
Author: Mark Wells <mark at freeside.biz>
Date: Tue Nov 1 01:47:22 2016 -0700
fix duplication of Washington sales taxes, #73185, fallout from #71501
diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm
index a1233d0..65fb722 100644
--- a/FS/FS/cust_main_county.pm
+++ b/FS/FS/cust_main_county.pm
@@ -682,6 +682,37 @@ END
}
+sub _merge_into {
+ # for internal use: takes another cust_main_county object, transfers
+ # all existing references to this record to that one, and deletes this
+ # one.
+ my $record = shift;
+ my $other = shift or die "record to merge into must be provided";
+ my $new_taxnum = $other->taxnum;
+ my $old_taxnum = $record->taxnum;
+ if ($other->tax != $record->tax or
+ $other->exempt_amount != $record->exempt_amount) {
+ # don't assume these are the same.
+ warn "Found duplicate taxes (#$new_taxnum and #$old_taxnum) but they have different rates and can't be merged.\n";
+ } else {
+ warn "Merging tax #$old_taxnum into #$new_taxnum\n";
+ foreach my $table (qw(
+ cust_bill_pkg_tax_location
+ cust_bill_pkg_tax_location_void
+ cust_tax_exempt_pkg
+ cust_tax_exempt_pkg_void
+ )) {
+ foreach my $row (qsearch($table, { 'taxnum' => $old_taxnum })) {
+ $row->set('taxnum' => $new_taxnum);
+ my $error = $row->replace;
+ die $error if $error;
+ }
+ }
+ my $error = $record->delete;
+ die $error if $error;
+ }
+}
+
sub _upgrade_data {
my $class = shift;
# assume taxes in Washington with district numbers, and null name, or
@@ -704,6 +735,28 @@ sub _upgrade_data {
}
FS::upgrade_journal->set_done($journal);
}
+ 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',
@@ -714,33 +767,10 @@ sub _upgrade_data {
# create an exact duplicate.
# so find the record this one would duplicate, and merge them.
$record->check; # trims whitespace
- my %match = map { $_ => $record->get($_) }
- qw(city county state country district taxname taxclass);
+ my %match = map { $_ => $record->get($_) } @key_fields;
my $other = qsearchs('cust_main_county', \%match);
if ($other) {
- my $new_taxnum = $other->taxnum;
- my $old_taxnum = $record->taxnum;
- if ($other->tax != $record->tax or
- $other->exempt_amount != $record->exempt_amount) {
- # don't assume these are the same.
- warn "Found duplicate taxes (#$new_taxnum and #$old_taxnum) but they have different rates and can't be merged.\n";
- } else {
- warn "Merging tax #$old_taxnum into #$new_taxnum\n";
- foreach my $table (qw(
- cust_bill_pkg_tax_location
- cust_bill_pkg_tax_location_void
- cust_tax_exempt_pkg
- cust_tax_exempt_pkg_void
- )) {
- foreach my $row (qsearch($table, { 'taxnum' => $old_taxnum })) {
- $row->set('taxnum' => $new_taxnum);
- my $error = $row->replace;
- die $error if $error;
- }
- }
- my $error = $record->delete;
- die $error if $error;
- }
+ $record->_merge_into($other);
} else {
# else there is no record this one duplicates, so just fix it
my $error = $record->replace;
diff --git a/FS/FS/geocode_Mixin.pm b/FS/FS/geocode_Mixin.pm
index a372faa..09b1131 100644
--- a/FS/FS/geocode_Mixin.pm
+++ b/FS/FS/geocode_Mixin.pm
@@ -273,7 +273,7 @@ sub process_district_update {
my $error = $self->replace;
die $error if $error;
- my %hash = map { $_ => $tax_info->{$_} }
+ my %hash = map { $_ => uc( $tax_info->{$_} ) }
qw( district city county state country );
$hash{'source'} = $method; # apply the update only to taxes we maintain
commit 30b057bd3af55b3438139486bd87d651540e674d
Author: Mark Wells <mark at freeside.biz>
Date: Tue Nov 1 01:47:20 2016 -0700
fix WA tax update script for some district numbers, #26265
diff --git a/bin/wa_tax_rate_update b/bin/wa_tax_rate_update
index 2d493db..fbca9dd 100644
--- a/bin/wa_tax_rate_update
+++ b/bin/wa_tax_rate_update
@@ -78,6 +78,7 @@ my $total_skipped = 0;
while ( !$csv->eof ) {
my $line = $csv->getline_hr($fh);
my $district = $line->{Code} or next;
+ $district = sprintf('%04d', $district);
my $tax = sprintf('%.1f', $line->{Rate} * 100);
my $changed = 0;
my $skipped = 0;
commit 4f8a5196a48ff735bbff2d17c96cd48e7ba54f4b
Author: Mark Wells <mark at freeside.biz>
Date: Tue Nov 1 01:43:59 2016 -0700
fix escaping
diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi
index 5226148..26a3e21 100755
--- a/httemplate/browse/cust_main_county.cgi
+++ b/httemplate/browse/cust_main_county.cgi
@@ -467,13 +467,13 @@ my @fields = (
? ' '. add_link(
desc => 'Add more counties',
col => 'state',
- label=> 'add more counties',
+ label=> 'add more counties',
row => $_[0],
cgi => $cgi,
).
' '. collapse_link(
col => 'state',
- label=> 'remove all counties',
+ label=> 'remove all counties',
row => $_[0],
cgi => $cgi,
)
@@ -484,7 +484,7 @@ my @fields = (
? ''
: ' '. expand_link( desc => 'Add States',
row => $_[0],
- label => 'add states',
+ label => 'add states',
cgi => $cgi,
)
);
@@ -503,18 +503,18 @@ my @fields = (
? ' '. add_link(
desc => 'Add more cities',
col => 'county',
- label=> 'add more cities',
+ label=> 'add more cities',
row => $_[0],
cgi => $cgi,
).
' '. collapse_link(
col => 'county',
- label=> 'remove all cities',
+ label=> 'remove all cities',
row => $_[0],
cgi => $cgi,
)
: ' '. remove_link( col => 'county',
- label=> 'remove county',
+ label=> 'remove county',
row => $_[0],
cgi => $cgi,
);
@@ -525,7 +525,7 @@ my @fields = (
: '(all) '.
expand_link( desc => 'Add Counties',
row => $_[0],
- label => 'add counties',
+ label => 'add counties',
cgi => $cgi,
);
},
@@ -541,7 +541,7 @@ my @fields = (
} else {
$r->city. ' '.
remove_link( col => 'city',
- label=> 'remove city',
+ label=> 'remove city',
row => $r,
cgi => $cgi,
);
@@ -550,7 +550,7 @@ my @fields = (
'(all) '.
expand_link( desc => 'Add Cities',
row => $r,
- label => 'add cities',
+ label => 'add cities',
cgi => $cgi,
);
}
@@ -562,7 +562,7 @@ my @fields = (
if ( $r->district ) {
$r->district . ' '.
remove_link( col => 'district',
- label=> 'remove district',
+ label=> 'remove district',
row => $r,
cgi => $cgi,
);
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_main_county.pm | 80 ++++++++++++++++++++++----------
FS/FS/geocode_Mixin.pm | 2 +-
bin/wa_tax_rate_update | 1 +
httemplate/browse/cust_main_county.cgi | 20 ++++----
4 files changed, 67 insertions(+), 36 deletions(-)
More information about the freeside-commits
mailing list