summaryrefslogtreecommitdiff
path: root/FS/FS/cust_bill_pkg.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-09-28 13:38:03 -0700
committerMark Wells <mark@freeside.biz>2012-09-28 13:38:03 -0700
commit962cd26e8e33bf3653cca439dbd9bd52f46bad29 (patch)
treebc56b8ca8244d7d3dde8d030af56501b9c5916ca /FS/FS/cust_bill_pkg.pm
parent2b4bb0058f931376a3169d596aa31a17e3f46b04 (diff)
auto-upgrade tax data from start of 2012, #940
Diffstat (limited to 'FS/FS/cust_bill_pkg.pm')
-rw-r--r--FS/FS/cust_bill_pkg.pm34
1 files changed, 27 insertions, 7 deletions
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index b8ae81d..20c8e5a 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -940,15 +940,14 @@ sub upgrade_tax_location {
# they were calculated on a package-location basis. Create them here,
# along with any necessary cust_location records and any tax exemption
# records.
- #
- # This probably shouldn't run from freeside-upgrade.
my ($class, %opt) = @_;
# %opt may include 's' and 'e': start and end date ranges
# and 'X': abort on any error, instead of just rolling back changes to
# that invoice
my $dbh = dbh;
- $FS::UID::AutoCommit = 0;
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
eval {
use FS::h_cust_main;
@@ -1108,7 +1107,8 @@ sub upgrade_tax_location {
push @{ $nontax_items{$taxclass} }, $item;
}
}
- printf("%d tax items: \$%.2f\n", scalar(@tax_items), map {$_->setup} @tax_items);
+ printf("%d tax items: \$%.2f\n", scalar(@tax_items), map {$_->setup} @tax_items)
+ if @tax_items;
# Use a variation on the procedure in
# FS::cust_main::Billing::_handle_taxes to identify taxes that apply
@@ -1378,21 +1378,41 @@ sub upgrade_tax_location {
} #foreach (@tax_links)
} #foreach $tax_item
- $dbh->commit if $commit_each_invoice;
+ $dbh->commit if $commit_each_invoice and $oldAutoCommit;
$committed = 1;
} #foreach $invnum
continue {
if (!$committed) {
- $dbh->rollback;
+ $dbh->rollback if $oldAutoCommit;
die "Upgrade halted.\n" unless $commit_each_invoice;
}
}
- $dbh->commit unless $commit_each_invoice;
+ $dbh->commit if $oldAutoCommit and !$commit_each_invoice;
'';
}
+sub _upgrade_data {
+ # Create a queue job to run upgrade_tax_location from January 1, 2012 to
+ # the present date.
+ eval {
+ use FS::queue;
+ use Date::Parse 'str2time';
+ };
+ my $class = shift;
+ my $upgrade = 'tax_location_2012';
+ return if FS::upgrade_journal->is_done($upgrade);
+ my $job = FS::queue->new({
+ 'job' => 'FS::cust_bill_pkg::upgrade_tax_location'
+ });
+ # call it kind of like a class method, not that it matters much
+ $job->insert($class, 's' => str2time('2012-01-01'));
+ # Then mark the upgrade as done, so that we don't queue the job twice
+ # and somehow run two of them concurrently.
+ FS::upgrade_journal->set_done($upgrade);
+}
+
=back
=head1 BUGS