5 Tests basic sales tax calculations, including consolidation and rounding.
6 The invoice will have two charges that add up to $50 and two taxes:
7 - Tax 1, 8.25%, for $4.125 in tax, which will round up.
8 - Tax 2, 8.245%, for $4.1225 in tax, which will round down.
10 Correct: The invoice will have one line item for each of those taxes, with
16 use Test::More tests => 2;
18 use Date::Parse 'str2time';
19 use Date::Format 'time2str';
20 use Test::MockTime qw(set_fixed_time);
24 my $FS= FS::Test->new;
28 [ 'Tax 1', 8.250, 4.13 ],
29 [ 'Tax 2', 8.245, 4.12 ],
32 # Create the customer and charge them
33 my $cust = $FS->new_customer('Basic taxes');
34 $cust->bill_location->state('AZ'); # move it away from the default of CA
36 $error = $cust->insert;
37 BAIL_OUT("can't create test customer: $error") if $error;
38 $error = $cust->charge( {
40 pkg => 'Test charge 1',
44 pkg => 'Test charge 2',
46 BAIL_OUT("can't create test charges: $error") if $error;
49 foreach my $tax (@taxes) {
50 my $cust_main_county = FS::cust_main_county->new({
53 'exempt_amount' => 0.00,
54 'taxname' => $tax->[0],
57 $error = $cust_main_county->insert;
58 BAIL_OUT("can't create tax definitions: $error") if $error;
62 set_fixed_time(str2time('2016-03-10 08:00'));
64 $error = $cust->bill( return_bill => \@return );
65 BAIL_OUT("can't bill charges: $error") if $error;
66 my $cust_bill = $return[0] or BAIL_OUT("no invoice generated");
68 diag("Tax on 25.00 + 25.00");
69 foreach my $cust_bill_pkg ($cust_bill->cust_bill_pkg) {
70 next if $cust_bill_pkg->pkgnum;
71 my ($tax) = grep { $_->[0] eq $cust_bill_pkg->itemdesc } @taxes;
73 ok ( $cust_bill_pkg->setup eq $tax->[2], "Tax at rate $tax->[1]% = $tax->[2]")
74 or diag("is ". $cust_bill_pkg->setup);