X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FLocation.pm;h=22feaf9c82ca65ab6d45042cbb7c7fa40ed77e23;hb=d62206a94d9d49ef96640e0a8ec492679f8345e9;hp=d1d6d67ffad1c25768e3fd0c1bf739b9d9b69d85;hpb=01629c3c934f1f6fd2ab9de5f7638f671fd59791;p=freeside.git diff --git a/FS/FS/cust_main/Location.pm b/FS/FS/cust_main/Location.pm index d1d6d67ff..22feaf9c8 100644 --- a/FS/FS/cust_main/Location.pm +++ b/FS/FS/cust_main/Location.pm @@ -8,7 +8,7 @@ use FS::cust_location; use Carp qw(carp); -$DEBUG = 1; +$DEBUG = 0; $me = '[FS::cust_main::Location]'; my $init = 0; @@ -18,7 +18,8 @@ BEGIN { no strict 'refs'; @location_fields = qw( address1 address2 city county state zip country district - latitude longitude coord_auto censustract censusyear geocode ); + latitude longitude coord_auto censustract censusyear geocode + addr_clean ); foreach my $f (@location_fields) { *{"FS::cust_main::Location::$f"} = sub { @@ -146,7 +147,7 @@ sub _upgrade_data { # just in case someone still doesn't have these if ( !$phone_type{$_}->phonetypenum ) { $error = $phone_type{$_}->insert; - die "error creating phone type '$_': $error"; + die "error creating phone type '$_': $error" if $error; } } @@ -156,27 +157,32 @@ sub _upgrade_data { my $bill_location = FS::cust_location->new( { custnum => $custnum, - map { $_ => $cust_main->get($_) } location_fields() + map { $_ => $cust_main->get($_) } location_fields(), } ); - $error = $bill_location->insert; - die "error migrating billing address for customer $custnum: $error" - if $error; - - $cust_main->set(bill_locationnum => $bill_location->locationnum); + $bill_location->set('censustract', ''); # properly goes with ship_location + my $ship_location = $bill_location; # until proven otherwise if ( $cust_main->get('ship_address1') ) { - my $ship_location = FS::cust_location->new( - { - custnum => $custnum, - map { $_ => $cust_main->get("ship_$_") } location_fields() + # detect duplicates + my $same = 1; + foreach (location_fields()) { + if ( length($cust_main->get("ship_$_")) and + $cust_main->get($_) ne $cust_main->get("ship_$_") ) { + $same = 0; } - ); - $error = $ship_location->insert; - die "error migrating service address for customer $custnum: $error" - if $error; + } + + if ( !$same ) { + $ship_location = FS::cust_location->new( + { + custnum => $custnum, + map { $_ => $cust_main->get("ship_$_") } location_fields() + } + ); + } # else it stays equal to $bill_location - $cust_main->set(ship_locationnum => $ship_location->locationnum); + $ship_location->set('censustract', $cust_main->get('censustract')); # Step 2: Extract shipping address contact fields into contact my %unlike = map { $_ => 1 } @@ -218,10 +224,20 @@ sub _upgrade_data { $cust_main->set("ship_$_" => '') foreach qw(last first company); } #if %unlike } #if ship_address1 - else { - $cust_main->set(ship_locationnum => $bill_location->locationnum); + $error = $bill_location->insert; + die "error migrating billing address for customer $custnum: $error" + if $error; + + $cust_main->set(bill_locationnum => $bill_location->locationnum); + + if (!$ship_location->locationnum) { + $error = $ship_location->insert; + die "error migrating service address for customer $custnum: $error" + if $error; } + $cust_main->set(ship_locationnum => $ship_location->locationnum); + # Step 3: Wipe the migrated fields and update the cust_main $cust_main->set("ship_$_" => '') foreach location_fields();