- $pre = 'ship_' if $use_ship and length($h_cust_main->get('ship_last'));
- my %hash = map { $_ => $h_cust_main->get($pre.$_) }
- FS::cust_main->location_fields;
- # not really needed for this, and often result in duplicate locations
- delete @hash{qw(censustract censusyear latitude longitude coord_auto)};
-
- $hash{custnum} = $h_cust_main->custnum;
- my $tax_loc = FS::cust_location->new(\%hash);
- my $error = $tax_loc->find_or_insert || $tax_loc->disable_if_unused;
- if ( $error ) {
- warn "couldn't create historical location record for cust#".
- $h_cust_main->custnum.": $error\n";
- next INVOICE;
+ my %tax_loc; # keys are pkgnums, values are cust_location objects
+ my $default_tax_loc;
+ if ( $h_cust_main->bill_locationnum ) {
+ # the location has already been upgraded
+ if ($use_ship) {
+ $default_tax_loc = $h_cust_main->ship_location;
+ } else {
+ $default_tax_loc = $h_cust_main->bill_location;
+ }
+ } else {
+ $pre = 'ship_' if $use_ship and length($h_cust_main->get('ship_last'));
+ my %hash = map { $_ => $h_cust_main->get($pre.$_) }
+ FS::cust_main->location_fields;
+ # not really needed for this, and often result in duplicate locations
+ delete @hash{qw(censustract censusyear latitude longitude coord_auto)};
+
+ $hash{custnum} = $h_cust_main->custnum;
+ $default_tax_loc = FS::cust_location->new(\%hash);
+ my $error = $default_tax_loc->find_or_insert || $default_tax_loc->disable_if_unused;
+ if ( $error ) {
+ warn "couldn't create historical location record for cust#".
+ $h_cust_main->custnum.": $error\n";
+ next INVOICE;
+ }