[freeside-commits] branch master updated. 7badb86e945f91ea4e18c8f52054d30404a43f86

Mark Wells mark at 420.am
Wed Apr 1 11:11:00 PDT 2015


The branch, master has been updated
       via  7badb86e945f91ea4e18c8f52054d30404a43f86 (commit)
      from  76d6fe17d02b77301619065ad43d7300432e977c (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 7badb86e945f91ea4e18c8f52054d30404a43f86
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Apr 1 13:07:01 2015 -0500

    fix post-consolidation linking of tax on tax records, should be the last piece of #34223

diff --git a/FS/FS/TaxEngine.pm b/FS/FS/TaxEngine.pm
index 0972fb7..54e305f 100644
--- a/FS/FS/TaxEngine.pm
+++ b/FS/FS/TaxEngine.pm
@@ -160,19 +160,27 @@ sub consolidate_taxlines {
   my %tax_amount;
 
   my $link_table = $self->info->{link_table};
+
+  # Preconstruct cust_bill_pkg objects that will become the "final"
+  # taxlines for each name, so that we can reference them.
+  # (keys are taxnames)
+  my %real_taxline_named = map {
+    $_ => FS::cust_bill_pkg->new({
+        'pkgnum'    => 0,
+        'recur'     => 0,
+        'sdate'     => '',
+        'edate'     => '',
+        'itemdesc'  => $_
+    })
+  } keys %taxname;
+
   # For each distinct tax name (the values set as $taxline->itemdesc),
   # create a consolidated tax item with the total amount and all the links
   # of all tax items that share that name.
   foreach my $taxname ( keys %taxname ) {
     my @tax_links;
-    my $tax_cust_bill_pkg = FS::cust_bill_pkg->new({
-        'pkgnum'    => 0,
-        'recur'     => 0,
-        'sdate'     => '',
-        'edate'     => '',
-        'itemdesc'  => $taxname,
-        $link_table => \@tax_links,
-    });
+    my $tax_cust_bill_pkg = $real_taxline_named{$taxname};
+    $tax_cust_bill_pkg->set( $link_table => \@tax_links );
 
     my $tax_total = 0;
     warn "adding $taxname\n" if $DEBUG > 1;
@@ -183,6 +191,16 @@ sub consolidate_taxlines {
       $tax_total += $taxitem->setup;
       foreach my $link ( @{ $taxitem->get($link_table) } ) {
         $link->set('tax_cust_bill_pkg', $tax_cust_bill_pkg);
+
+        # if the link represents tax on tax, also fix its taxable pointer
+        # to point to the "final" taxline
+        my $taxable_cust_bill_pkg = $link->get('taxable_cust_bill_pkg');
+        if (my $other_taxname = $taxable_cust_bill_pkg->itemdesc) {
+          $link->set('taxable_cust_bill_pkg',
+            $real_taxline_named{$other_taxname}
+          );
+        }
+
         push @tax_links, $link;
       }
     } # foreach $taxitem
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index 156ab5b..d0cec90 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -207,6 +207,7 @@ sub insert {
   {
     my $tax_location = $self->get($tax_link_table) || [];
     foreach my $link ( @$tax_location ) {
+      $DB::single=1; #XXX
       my $pkey = $link->primary_key;
       next if $link->get($pkey); # don't try to double-insert
       # This cust_bill_pkg can be linked on either side (i.e. it can be the
@@ -238,12 +239,12 @@ sub insert {
           return "error inserting cust_bill_pkg_tax_location: $error";
         }
       } else { # handoff
-        my $other;
+        my $other; # the as yet uninserted cust_bill_pkg
         $other = $link->billpkgnum ? $link->get('taxable_cust_bill_pkg')
                                    : $link->get('tax_cust_bill_pkg');
-        my $link_array = $other->get('cust_bill_pkg_tax_location') || [];
+        my $link_array = $other->get( $tax_link_table ) || [];
         push @$link_array, $link;
-        $other->set('cust_bill_pkg_tax_location' => $link_array);
+        $other->set( $tax_link_table => $link_array);
       }
     } #foreach my $link
   }

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

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




More information about the freeside-commits mailing list