[freeside-commits] branch master updated. 962cd26e8e33bf3653cca439dbd9bd52f46bad29

Mark Wells mark at 420.am
Fri Sep 28 13:38:20 PDT 2012


The branch, master has been updated
       via  962cd26e8e33bf3653cca439dbd9bd52f46bad29 (commit)
      from  2b4bb0058f931376a3169d596aa31a17e3f46b04 (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 962cd26e8e33bf3653cca439dbd9bd52f46bad29
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Sep 28 13:38:03 2012 -0700

    auto-upgrade tax data from start of 2012, #940

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index b7971ff..7dd889f 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -290,6 +290,9 @@ sub upgrade_data {
 
     #flag monthly tax exemptions
     'cust_tax_exempt_pkg' => [],
+
+    #kick off tax location history upgrade
+    'cust_bill_pkg' => [],
   ;
 
   \%hash;
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

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Upgrade.pm       |    3 +++
 FS/FS/cust_bill_pkg.pm |   34 +++++++++++++++++++++++++++-------
 2 files changed, 30 insertions(+), 7 deletions(-)




More information about the freeside-commits mailing list