[freeside-commits] branch master updated. e71dd08fc2e0aa3ee8cdbeb4e1f39f04898f773b

Mark Wells mark at 420.am
Tue Oct 18 23:14:46 PDT 2016


The branch, master has been updated
       via  e71dd08fc2e0aa3ee8cdbeb4e1f39f04898f773b (commit)
      from  068b074adcb3cd0c4d0b39d407c7bb2272a9cade (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 e71dd08fc2e0aa3ee8cdbeb4e1f39f04898f773b
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Oct 18 23:06:03 2016 -0700

    during upgrade, fix broken tax links on old voided invoices, #72777

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 1c1095e..8452086 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -388,6 +388,7 @@ sub upgrade_data {
     # reason / void_reason migration to reasonnum / void_reasonnum
     'cust_credit_void' => [],
     'cust_bill_void' => [],
+    # also fix some tax allocation records
     'cust_bill_pkg_void' => [],
 
     #duplicate history records
diff --git a/FS/FS/cust_bill_pkg_void.pm b/FS/FS/cust_bill_pkg_void.pm
index 991dd37..9bfd41f 100644
--- a/FS/FS/cust_bill_pkg_void.pm
+++ b/FS/FS/cust_bill_pkg_void.pm
@@ -13,6 +13,7 @@ use FS::cust_bill_pkg_fee;
 use FS::cust_bill_pkg_tax_location;
 use FS::cust_bill_pkg_tax_rate_location;
 use FS::cust_tax_exempt_pkg;
+use FS::Cursor;
 
 $me = '[ FS::cust_bill_pkg_void ]';
 $DEBUG = 0;
@@ -283,7 +284,6 @@ sub cust_bill_pkg_fee {
   qsearch( 'cust_bill_pkg_fee_void', { 'billpkgnum' => $self->billpkgnum } );
 }
 
-
 # _upgrade_data
 #
 # Used by FS::Upgrade to migrate to a new database.
@@ -293,6 +293,33 @@ sub _upgrade_data {  # class method
   warn "$me upgrading $class\n" if $DEBUG;
 
   $class->_upgrade_reasonnum(%opts);
+  my $error;
+  # fix voids with tax from before July 2013, when the taxable_billpkgnum
+  # field was added to the void table
+  my $search = FS::Cursor->new({
+    'table'   => 'cust_bill_pkg_tax_location_void',
+    'hashref' => { 'taxable_billpkgnum' => '' }
+  });
+  while (my $void = $search->fetch) {
+    # the history for the unvoided record should have the correct
+    # taxable_billpkgnum
+    my $num = $void->billpkgtaxlocationnum;
+    my $unvoid = qsearchs({
+      'table'   => 'h_cust_bill_pkg_tax_location',
+      'hashref' => { 'billpkgtaxlocationnum' => $num },
+      'order_by' => ' ORDER BY history_date DESC LIMIT 1'
+    });
+    if (!$unvoid) {
+      # should never happen
+      die "billpkgtaxlocationnum $num: could not find pre-void history record to restore taxable_billpkgnum.";
+    }
+    if ($unvoid) {
+      $void->set('taxable_billpkgnum', $unvoid->taxable_billpkgnum);
+      $error = $void->replace;
+      die "billpkgtaxlocationnum $num: $error\n" if $error;
+    }
+  }
+
 }
 
 =back

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

Summary of changes:
 FS/FS/Upgrade.pm            |    1 +
 FS/FS/cust_bill_pkg_void.pm |   29 ++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list