Allow alternations in the tax data, so that it is case insensitive

and allows multiple definitions of an entry (like state, city or country)
This commit is contained in:
Colin Kuskie 2008-03-07 02:16:40 +00:00
parent 50fc494759
commit 52cf8b672c
4 changed files with 64 additions and 7 deletions

View file

@ -36,7 +36,7 @@ my $session = WebGUI::Test->session;
my $addExceptions = getAddExceptions($session);
my $tests = 68 + 2*scalar(@{$addExceptions});
my $tests = 72 + 2*scalar(@{$addExceptions});
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -209,6 +209,23 @@ my $wiData = $taxer->getItems->hashRef;
##Need to ignore the taxId from the database
cmp_bag([ @{ $wiData }{ @expectedHeader } ], \@row1, 'exportTaxData: first line of data is correct');
my $newTaxId = $taxer->add({
country => 'USA|U.S.A.',
state => 'washington|WA',
taxRate => '7',
code => '',
city => '',
});
$taxer->delete({taxId => $wisconsinTaxId});
$storage = $taxer->exportTaxData();
@fileLines = split /\n+/, $storage->getFileContentsAsScalar('siteTaxData.csv');
my @row1 = WebGUI::Text::splitCSV($fileLines[1]);
my $wiData = $taxer->getItems->hashRef;
##Need to ignore the taxId from the database
cmp_bag([ @{ $wiData }{ @expectedHeader } ], \@row1, 'exportTaxData: first line of data is correct');
$taxer->delete({taxId => $newTaxId});
#######################################################################
#
# import
@ -392,6 +409,27 @@ cmp_deeply(
'importTaxData: error handling for a file with a bad header',
);
ok(
$taxer->importTaxData(
WebGUI::Test->getTestCollateralPath('taxTables/alternations.csv')
),
'Tax data with alternations inserted',
);
my $altData = $taxer->getItems->hashRef; ##Just 1 row
cmp_deeply(
$altData,
{
taxId => ignore,
country => q{U.S.A.,USA},
state => q{WI,Wisconsin},
city => q{Madison},
code => 53701,
taxRate => 0.5,
},
'import: Data correctly loaded with alternations'
);
#######################################################################
#
# getTaxRates
@ -417,6 +455,13 @@ my $taxFreeAddress = $book->addAddress({
code => '97123',
country => 'USA',
});
my $alternateAddress = $book->addAddress({
label => 'using alternations',
city => 'Los Angeles',
state => 'CalifornIA',
code => '97123',
country => 'U.S.A.',
});
eval { $taxer->getTaxRates(); };
$e = Exception::Class->caught();
@ -443,6 +488,12 @@ cmp_deeply(
'getTaxRates: return correct data for a state with no tax data'
);
cmp_deeply(
$taxer->getTaxRates($alternateAddress),
[7.25], #Only 7.25 because it uses the alternate address for USA
'getTaxRates: return correct data for a state when the address has alternations'
);
#######################################################################
#
# calculate

View file

@ -0,0 +1,2 @@
country,state,city,code,taxRate
U.S.A.|USA,WI|Wisconsin,Madison,53701,0.5
1 country state city code taxRate
2 U.S.A.|USA WI|Wisconsin Madison 53701 0.5

View file

@ -5,5 +5,5 @@ USA,WI,,53701,0.5
USA,WI,,53702,0.5
USA,WI,,53703,0.5
USA,WI,,53704,0.5
USA,CA,,,7.25
USA|U.S.A.,CA|California,,,7.25
USA,,,97123,0.0

1 country state city code taxRate
5 USA WI 53702 0.5
6 USA WI 53703 0.5
7 USA WI 53704 0.5
8 USA USA|U.S.A. CA CA|California 7.25
9 USA 97123 0.0