fix bad merge
[freeside.git] / FS / FS / TaxEngine / internal.pm
index 60f7aad..99535ad 100644 (file)
@@ -15,18 +15,17 @@ my %part_pkg_cache;
 
 sub add_sale {
   my ($self, $cust_bill_pkg) = @_;
-  my $cust_pkg = $cust_bill_pkg->cust_pkg;
-  my $pkgpart = $cust_bill_pkg->pkgpart_override || $cust_pkg->pkgpart;
-  my $part_pkg = $part_pkg_cache{$pkgpart} ||= FS::part_pkg->by_key($pkgpart)
-    or die "pkgpart $pkgpart not found";
-  push @{ $self->{items} }, $cust_bill_pkg;
 
-  my $location = $cust_pkg->tax_location; # cacheable?
+  my $part_item = $cust_bill_pkg->part_X;
+  my $location = $cust_bill_pkg->tax_location;
+  my $custnum = $self->{cust_main}->custnum;
+
+  push @{ $self->{items} }, $cust_bill_pkg;
 
   my @loc_keys = qw( district city county state country );
   my %taxhash = map { $_ => $location->get($_) } @loc_keys;
 
-  $taxhash{'taxclass'} = $part_pkg->taxclass;
+  $taxhash{'taxclass'} = $part_item->taxclass;
 
   my @taxes = (); # entries are cust_main_county objects
   my %taxhash_elim = %taxhash;
@@ -46,9 +45,10 @@ sub add_sale {
     $taxhash_elim{ shift(@elim) } = '';
   } while ( !scalar(@taxes) && scalar(@elim) );
 
-  foreach (@taxes) {
-    my $taxnum = $_->taxnum;
-    $self->{taxes}->{$taxnum} ||= [ $_ ];
+  foreach my $tax (@taxes) {
+    my $taxnum = $tax->taxnum;
+    $self->{taxes}->{$taxnum} ||= [ $tax ];
+    $cust_bill_pkg->set_exemptions( $tax, 'custnum' => $custnum );
     push @{ $self->{taxes}->{$taxnum} }, $cust_bill_pkg;
   }
 }